PRIME NUMBER SERIES - C-Tutorial

Latest

Monday, 26 September 2016

PRIME NUMBER SERIES

/* SERIES OF PRIME NUMBERS IN GIVEN RANGE */


#include<conio.h>
main()
{
int n,i,j,count=0;
clrscr();
printf("\n Enter n value:");
scanf("%d",&n);
if(n<=1)
{
printf("\n There are no prime numbers below one");
}
else
{
printf("\n\n The prime numbers are:\n ");
}
if(n>=2)
{
for(i=1;i<=n;i++)
{
count=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==2)
{
printf("%3d",i);
}
}
}
getch();
}

No comments:

Post a Comment