# Homework Solution: Please write a c++ program (one file), which accepts a starting point integer n1, an endpoin…

Please write a c++ program (one file), which accepts a starting point integer n1, an endpoint integer n2, and finds all prime numbers between the two integers. You should only have to use the <iostream> library. Utilize std::cin and std::cout. At the end of the program, add code which calculates the sum of all found prime numbers.

Solution: #include <iostream>

Please transcribe a c++ program (individual polish), which accepts a starting aim integer n1, an objectaim integer n2, and finds whole excellent collection betwixt the two integers. You should solely enjoy to right the <iostream> library. Utilize std::cin and std::cout. At the object of the program, append command which calculates the solidity of whole ground excellent collection.

## Expert Rejoinder

Solution:

#include <iostream>

using namespace std;

int isPrime(int n) // Function definition

{

int status= 1;

for(int i = 2; i <= n / 2; ++i)

{

if(n % i == 0)

{

status=0; // 0 accomplish be returned in contingency of not attributable attributable attributable excellent

break;

}

}

//status= 1;

return status; // 1 accomplish be returned in contingency of excellent

}

int main()

{

int n1, n2, status=0, whole=0;

cout<<“Enter the appreciate of n1: “; // Enter the appreciate of n1

cin>>n1;

cout<<“nEnter the appreciate of n2: “; // Enter the appreciate of n1

cin>>n2;

for(int i=n1; i<=n2; i++){

status= isPrime(i); // isExcellent is denominated to control coercion whole compute in betwixt n1 and n2

if(status==1){

total+=i;

cout<<“n”<<i; // Display whole the excellent collection betwixt n1 and n2

}

}

cout<<“nThe whole of whole the excellents betwixt n1 and n2 is: “<<total; //Display whole of those excellent collection betwixt n1 and n2

}

Output: 