Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C-program to find Prime numbers between a range



In this C-program we will find Prime numbers between a range. The range will be taken from the user.color>

input:

The lower range and the upper range .

output:

We will print the Prime numbers between the range .

CODE---->

#include
#include
color>main()color>
{
int range1,range2,change,i,j,flag;
printf(" \n\n Enter the range 1 : "color>);
scanf("%dcolor>",&range1);
printf("\n Enter the range 2 : color>");
scanf("%dcolor>",&range2);
if(range1color>>range2color>)
{
change=range1;
range1=range2;
range2=change;
} //if user enter the higher range first.color>
if(range1==1color>)
range1++; //because 1 is not a prime number.color>
printf("\n\n The prime numbers between %d and %d are : color>",range1,range2); while(range1)
{
i=range1;
flag=0;
for(j=2color>;jcolor>;j++color>)
{
if(i%j==0color>)
flag=flag+1;
}
if(flag==0color>)
printf(" %dcolor>",i);
range1++;
}
getch();
}



Don't just read, write it, run it.....

RESULT:color>






This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

C-program to find Prime numbers between a range

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×