Friday 24 July 2015

C Program - To check the prime numbers between a given range

C Program to check the prime numbers between a given range



#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,c,b=0,n,m,count=0;
clrscr();
printf("\nEnter the starting number :- ");
scanf("%d",&n);
printf("\nEnter the ending number :- ");
scanf("%d",&m);
printf("\nPrime numbers between the given range are :- \n");
for(i=n;i<m;i++)
{
c=i;
for(j=2;j<c;j++)
{
    if(c%j==0)
    {
b=1;
break;
    }
}
if(b==0)
{
printf(" %d",c);
count++;
}
b=0;
}
printf("\n\nTotal number of prime number is :- %d",count);
getch();
}

Output :-




Back to 'C Language Programs'

No comments:

Post a Comment