Wednesday, April 6, 2016

W.A.P that prints Prime Number from 1 to N.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,c;
clrscr();
printf("enter value of n : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c++;
}
}
if(c==2)
{
if(i!=2)
printf(", ");
printf("%d",i);

}
}

getch();
}

No comments:

Post a Comment