Search This Blog

Showing posts with label print all prime numbers till n. Show all posts
Showing posts with label print all prime numbers till n. Show all posts

Sunday, April 3, 2011

to print all prime numbers till n

#include <stdio.h>
main()
{
int n,i=1,j,c;
clrscr();
printf("Enter Number Of Terms");
scanf("%d",&n);
printf("Prime Numbers Are Follwing");
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d\t",i);
i++;
}
getch();
}