Pages

Custom Search

Tuesday, October 11, 2011

Program to generate superprime numbers in a given range.


//Program to generate superprimes in a given range and display the number of superprimes.
//leave space between lower limit and upper limit

#include<stdio.h>
#include<conio.h>

void superprime();                   //Function declaration

int main()
{
int  sn, en;
printf("\nEnter range of numbers: ");
scanf("%d %d", &sn, &en);

superprime(sn, en);                 //Function call

getch();
}
void superprime(int sn, int en)
{
int a, digit, d=2, flag=1, f=1, t, i, c=0;;

for(i=sn;i<=en;i++)
{
t=i;
flag=1;
d=2;
while(d<t)
{
if((t%d)==0)
{
flag=0;
break;
}
d++;
}
if(flag==1)
{
while(t>0)
{
a=2;
digit=t%10;
f=1;
while(a<digit)
{
if((digit%a)==0)
{
f=0;
break;
}
a++;
}
t=t/10;
if(f==0)
break;
}
if(f==1)
{
printf("%d\t", i);
c++;
}
}
}
printf("\n\nNumber of superprimes: %d\n", c);
}

SAMPLE OUTPUT:



2 comments:

Anonymous said...

Does the sentence "leave space for upper limit and lower limit" part of the program? One more, how can i be able to put the range of the numbers? From 10,000 to 100,000? Can you display the exact program of it? If you don't mind? Thanks. :D

Unknown said...

Sorry for the late reply. Had exams going on..
Ways "leave space for upper limit and lower limit" is not a part of the program... have commented that line.
And i guess the sample output which I have displayed is clear enough for you to understand how the range should be given. It should be " 10000 100000 " without the quotes and commas should not be used...

Custom Search