Write a program to print all the prime numbers with in the
given range
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
3.write a simple program that will output your name,phone number,e-mail address,and academic major on separate lines 1.create an account and a personal directory for your work b.find out how to create a subdirectory on your system.create one called info c.you will use a text editor to type in your programs and data files.some C systems have a built in text editor;others do not.Find out what text editor you will be using and how to access it.create a text file(not a program) containing your name ,address,and telephone number on separate lines.Next,write the brand of computer you are using and the name of the text editor.Then write a paragraph that describes your past experience with computers.save this file in your info directory. d. find out how to print a file on your system .print out and turn in the file you created in (c).
What is putchar() function?
write a program to swap two variables a=5 , b= 10 without using third variable
What is the collection of communication lines and routers called?
what is the role you expect in software industry?
What do you mean by command line argument?
how to find greatet of 10 numbers without using array?
How to reverse a string using a recursive function, without swapping or using an extra memory?
31 Answers Cisco, Mind Tree, Motorola, Ophio, Sony, TCS, Wipro,
Explain how do you sort filenames in a directory?
One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.
which will be first in c compiling ,linking or compiling ,debugging.
What is %d called in c?