Testing.

Sunday, 22 January 2017

C programming language: Write a prime number program in c.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,n1,n2,t,cnt=0,flag;
printf("\nEnter Two Values: ");
scanf("%d%d",&n1,&n2);
for(n=n1;n<=n2;n++)
{
flag=0;
for(t=2;t<n/2;t++)
{
if(n%t==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("\n%d. Prime Number: %d",++cnt,n);
}
getch();
}

No comments:

Post a Comment