//Display Prime Numbers Between two Intervals
#include <iostream>
using namespace std;
int main()
{
int start, num, end, i, flag;
cout << "Enter two numbers(intervals): ";
cin >> start >> end;
cout << "Prime numbers between " << start << " and "
<< end << " are: ";
while (start < end)
{
flag = 0;
num=start;
for(i = 2; i <= num/2; ++i)
{
if(num % i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
cout << num << " is a prime number\n ";
++start;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int start, num, end, i, flag;
cout << "Enter two numbers(intervals): ";
cin >> start >> end;
cout << "Prime numbers between " << start << " and "
<< end << " are: ";
while (start < end)
{
flag = 0;
num=start;
for(i = 2; i <= num/2; ++i)
{
if(num % i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
cout << num << " is a prime number\n ";
++start;
}
return 0;
}
No comments:
Post a Comment