C is the programming language Write a program that prints al

C++ is the programming language

Write a program that prints all the prime numbers in the range of two user defined numbers: low and high. Create a function that checks for a number to be prime or not.

Example:

Enter lower limit? 5

Enter higher limit?30

List of prime numbers in the above range is: 5 7 11 13 17 19 23 29

Solution

#include <iostream>
#include <iomanip>
#include<string>

using namespace std;

bool isPrime(int n)
{
int i = 0;
for(i=2;i<n;i++)
if(n%i==0)
return false;
  
return true;
}

int main() {
//declare variables
int low,high;
  
cout << \"Enter lower limit : \";
cin >> low;
  
cout << \"Enter higher limit : \";
cin >> high;
  
int i = 0;
cout << \"\ List of prime numbers in the above range is:\";
for(i=low;i<=high;i++)
{
if(isPrime(i))
cout << i << \" \";
}
return 0;
}//End of Main function

C++ is the programming language Write a program that prints all the prime numbers in the range of two user defined numbers: low and high. Create a function that

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site