29. How to print prime number.

Print Prime Numbers(using for loop):

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
clrscr();
int i,j,n;
printf("Enter a value : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
 {
 for(j=2;j<=sqrt(i);j++)
   {
   if(i%j==0)
     break;
     if(j>sqrt(i))
     printf("%d  ",i);
   }
 }
getch();
}
post by Arnob.

No comments:

Post a Comment

free counters