Write a program to print all the prime numbers with in the
given range

Answer Posted / smi

/* Program to print all prime number between a range through
function */
#include
#include
void print_prime(int r1,int r2)
{
int n=0,d=0,j;
clrscr();
for(n=r1;n<=r2;++n)
{
for(j=2;j
{
if(n%j==0)
{
d++;
break;
}
}
if(d==0)
printf("\t%d",n);
d=0;
}
}
void main()
{
int n1=0,n2=0;
printf("\n Enter range1 & range2 =>");
scanf("%d%d",&n1,&n2);
print_prime(n1,n2);
getch();
}

Is This Answer Correct ?    26 Yes 47 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Compare array data type to pointer data type

585


Is null valid for pointers to functions?

594


What is build process in c?

632


How can I rethow can I return a sequence of random numbers which dont repeat at all?

693


What is use of pointer?

575






Can you please explain the scope of static variables?

590


What are multidimensional arrays?

646


Write a program to print "hello world" without using a semicolon?

585


What are the different types of control structures in programming?

647


Are local variables initialized to zero by default in c?

537


Explain data types & how many data types supported by c?

568


What is the condition that is applied with ?: Operator?

651


Why main is not a keyword in c?

635


What language is c written?

564


Explain how do you generate random numbers in c?

608