Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<iostream> using namespace std; // using cout statements int main() // m

ID: 3651584 • Letter: #

Question

#include<iostream>
using namespace std; // using cout statements
int main() // main function
{
int n; //declaring variables
int i;
int x;
int count;
int temp;

cout << "Give me an integer n: " << endl; // prompts the user to enter an integer
cin >> n; //stores the entered value

for(i=3; i<=n; i++)//find the factors of i while updating the value of i with this for loop
{
count = 1;
temp = 0;
for(x=2; x<i; x++) {
if((i%x) == 0){
temp++;
}
}
if (temp == 0) {
count++;
}
}
cout << "There are " << count << " primes(s) less than or equal to "<< n <<endl;
return 0; // end function
}

this is what I have and it always prints only 1 prime number being found what is wrong?

Explanation / Answer

#include using namespace std; // using cout statements int main() // main function { int n; //declaring variables int i; int x; int count; int temp; cout