Wednesday, 28 August 2013

Generate the first 'n' prime numbers.

#include <stdio.h>
void main()
{
int i,j,n,count;
printf("enter the last no upto which want prime nos:\n");
scanf("%d",&n);
printf("prime nos from 0 to %d are:\n",n);
for(i=1;i<=n;i++)
{
count=0;
for(j=1;j<=i;j++)
{
if((i%j)==0)
count++;
}
if(count==2)
printf("%d ",i);
}
}

No comments:

Post a Comment