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 ?    30 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 ?    5 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 ?    1 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 when is a void pointer used?

0 Answers  


How does free() know how many bytes to free?

8 Answers  


How do you convert strings to numbers in C?

0 Answers  


please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................

0 Answers  


what is ram?

3 Answers   TCS,






How do I copy files?

0 Answers  


Write a program that receives as input a number omaadel-n-print, four digits.

0 Answers  


2)#include<iostream.h> main() { printf("Hello World"); } the program prints Hello World without changing main() the o/p should be intialisation Hello World Desruct the changes should be a)iostream operator<<(iostream os, char*s) os<<'intialisation'<<(Hello World)<<Destruct b) c) d)none of the above

4 Answers   Siemens,


char p="data"; printf(p);

2 Answers  


pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)

0 Answers   Subex,


6)What would be the output? main() { int u=1,v=3; pf("%d%d",u,v); funct1(&u,&v); pf("%d%d\n",u,v); } void funct1(int *pu, int *pv) { *pu=0; *pv=0; return; } a)1 3 1 3 b)1 3 1 1 c)1 3 0 0 d)1 1 1 1 e) 3 1 3 1

4 Answers  


to find the closest pair

0 Answers   Infosys,






Categories