Răspunsuri

2014-02-19T23:03:56+02:00
#include "stdio.h"
#include "conio.h"

int prim(int x){int ok=1;for (int i=2;i<=x/2;i++) if (x%i==0) ok=0;return ok;}
int suma_cifre(int m){int s,c;s=0;do{c=m%10; s=s+c; m=m/10;}while (m!=0);return s;}
int nr_cifre(int m){int nr=0;do {nr++;m=m/10;} while (m!=0);return nr;}
double putere(int x){double prod;prod=1;do{prod=10*prod;x--;}while (x!=0);return prod;}
void afisare(int k,int n){ double nr_max; nr_max=putere(n)-1; for (int i=2;i<=nr_max;i++) if ((prim(i)==1)&&(suma_cifre(i)<k) && (nr_cifre(i)==n)) printf("\nnr prim: %i",i);
}
void main(){int m,n;printf("\n Suma cifrelor:");scanf("%i",&m);printf("\n Nr de cifre:");scanf("%i",&n);afisare(m,n);getch();}