#include<iostream> using namespace std; // using cout statements int main() // m
ID: 3651568 • 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
}
how do i fix my code to count all of the primes leading up to the number entered it only counts one. what is the code for this?
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; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.