This is from C++ Programming Edition 5 by D.S. Malik Chapter 5 question 7, the c
ID: 3634546 • Letter: T
Question
This is from C++ Programming Edition 5 by D.S. Malik Chapter 5 question 7, the code posted on this site (that I paid for) doesn't even work you are to write a program to determine if a number is a prime number or not, asking the user for a positive integer and outputting a message whether its a prime number or not:
#include <cstdlib>
#include <iostream>
using namespace std;
void main()
{
int num; //store a number variable
int i; //variable for loop
int count;
cout<<"Enter a number to determine if it is a prime number:"<<endl;
cin>>num
count=0
//procedure to find if number is prime
for (i=2;i<num/2;i++)
{
if(num%i==0)
count++;
} //end for statement
if(count>0)
cout<<"The number "<<num<<"is a Prime Number"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Explanation / Answer
#include #include using namespace std; void main() //return type is void and you are returning a value in last line { int num; //store a number variable int i; //variable for loop int count; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.