Acasa Tehnologie Afisarea primelor n numere prime

Afisarea primelor n numere prime

by Dragos Schiopu

>

#include <stdio.h>
#include <conio.h>
#include <math.h>

main()
{
//se tiparesc primele n nr prime
int ok,x,k,poz;
printf("Dati x=");
scanf("%d",&x);
k=1; poz=1;

do
{
ok=1;
for (int i=2; i<=sqrt(k);i++)
if (k%i==0) ok=0;
if (ok==1) { printf(" %d ",k); k++; poz++; }
else k++;
}
while(x>=poz);
getch();
return 0;
}

s-ar putea sa-ti placa

0 comentarii

Skull377 22-01-2011 - 12:03
admin 22-01-2011 - 12:06