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

Answers were Sorted based on User's Feedback



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

Answer / roopa

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


main()

{
int n1=0,n2=0;
printf("enter the range\n");
scanf("%d %d", &n1, &n2);
prime(n1,n2);
getch();
}

int prime(int n1, int n2)
{

int i,j;
for (i=n1;i<=n2;++i)

{
for(j=2;j<=(i/2);j++)
{
if(i%j==0)
{

break;
}
}
if(j==(i/2+1))
printf("%d\n", i);

}
}

Is This Answer Correct ?    31 Yes 17 No

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

Answer / om

void find_primenumber_in_range(int r1,int r2)
{
int i,j;
for(i=r1;i<=r2;i++)
{
for(j=2; j<=(i/2); j++)
if(i%j==0)
break;
if(j== (i/2 +1))
printf("%d\t",i);
}
}

Is This Answer Correct ?    31 Yes 21 No

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

Answer / don

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

main()
{
int i, p, q;
int count;
printf("Enter lower Limit: ");
scanf("%d",&p);
printf("Enter Upper Limit: ");
scanf("%d",&q);
i=p;
while(i<=q)
{
for(count=2; count<i; count++)
{
if(i%count == 0)
goto line;
else
continue;
}
printf("%d ",i);
line: i++;
}

getch();
}

Is This Answer Correct ?    6 Yes 4 No

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

Answer / pooja mishra

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int range,c;
cout<<"enter the range";
cin>>range;
for(int i=1;i<=range;i++)
{
c=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
c++;
}
if(c==o)
cout<<i<<"\n";
}
getch();
}

Is This Answer Correct ?    2 Yes 1 No

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

Answer / ankit giriya

#include<stdio.h>
void main()
{
int i, prime, lim_up, lim_low, n;
clrscr();
printf(“\n\n\t ENTER THE LOWER LIMIT…: “);
scanf(“%d”, &lim_low);
printf(“\n\n\t ENTER THE UPPER LIMIT…: “);
scanf(“%d”, &lim_up);
printf(“\n\n\t PRIME NUMBERS ARE…: “);
for(n=lim_low+1; n<lim_up; n++)
{
prime = 1;
for(i=2; i<n; i++)
if(n%i == 0)
{
prime = 0;
break;
}
if(prime)
printf(“\n\n\t\t\t%d”, n);
}
getch();
}

Is This Answer Correct ?    4 Yes 5 No

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

Answer / chavidi

void prime(int a,int b)
{
int i,j,c
for(i=a;i<=b;i++)
{
c=0;
for(j=1;j<=a;j++)
{
if(a%j==0)
{
c++;
}
}
if(c==2)
printf(i);
}
}

Is This Answer Correct ?    8 Yes 14 No

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

Answer / vaibhav

need to check only odd no.s in the given range....this'll
dec. time complexity to some extent..

Is This Answer Correct ?    4 Yes 12 No

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

Answer / 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

More C Interview Questions

Tell me can the size of an array be declared at runtime?

0 Answers  


Is c high or low level?

0 Answers  


how will you write a program on linked lists using JAVA programming???????????

1 Answers   Keane India Ltd,


Difference Between embedded software and soft ware?

1 Answers   Bosch,


Why is malloc used?

1 Answers  






Do you know the difference between malloc() and calloc() function?

0 Answers  


Can 'this' pointer by used in the constructor?

0 Answers  


What does extern mean in a function declaration?

4 Answers  


What is a list in c?

0 Answers  


Which of these statements are false w.r.t File Functions? i)fputs() ii)fdopen() iii)fgetpos() iv)ferror() A)ii B)i,ii C)iii D)iv

6 Answers   Accenture,


What are header files why are they important?

0 Answers  


How to write the code of the program to swap two numbers with in one statement?

2 Answers  


Categories