Google Ads

Wednesday, May 27, 2009

Prime Number

PRIME NUMBER GENERATION

#include”stdio.h”
#include “conio.h”
void main()
{
int i,j,c,n;
clrscr();
printf("Enter the limit,to generate prime no's for given value : ");
scanf("%d",&n);
printf("\n\nThe Prime number upto %d : ",n);
for(i=2;i<=n;i++) { c=0; for(j=2;j
{
if(i%j==0)
{
c=c+1;
}
}
if(c==0)
{
printf(" %d",i);
}
}
getch();
}


Output will be

Enter the limit, to generate prime no's for given value : 6

The Prime number’s upto 6 : 2 3 5

No comments:

Post a Comment