#include <iostream>
using namespace std;
void main()
{
int num,i,ctr,stno,enno;
cout<<"Input starting number of range: ";
cin>>stno;
cout<<"Input ending number of range : ";
cin>>enno;
cout<<"The prime numbers between : "<<stno<<"and"<<enno<<endl;
for(num = stno;num<=enno;num++)
{
ctr = 0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
ctr++;
break;
}
}
if(ctr==0 && num!= 1)
cout<<" "<<num;
}
cout<<endl;
system ("pause");
}
using namespace std;
void main()
{
int num,i,ctr,stno,enno;
cout<<"Input starting number of range: ";
cin>>stno;
cout<<"Input ending number of range : ";
cin>>enno;
cout<<"The prime numbers between : "<<stno<<"and"<<enno<<endl;
for(num = stno;num<=enno;num++)
{
ctr = 0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
ctr++;
break;
}
}
if(ctr==0 && num!= 1)
cout<<" "<<num;
}
cout<<endl;
system ("pause");
}
Test Data :
Input starting number of range: 1
Input ending number of range : 50
Expected Output :
The prime number between 1 and 50 are :
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
Write a program in C++ to find the prime numbers within a range of numbers
Reviewed by Unknown
on
May 30, 2017
Rating:
No comments: