i want to create a program that prompt the user to input positive number and the
ID: 3621256 • Letter: I
Question
i want to create a program that prompt the user to input positive number and then output if it is prime number or not.but iwant to solve it just with using include <iostream>
and i start the program like this:
#include<iostream>
using namespace std;
int main ()
{
int number,oddnumber;
cout<<"please enter a positive number"<<endl;
while (number<=0)
{
cout<<" please re-enter positiv2e number ";
cin>>number;
}
if (number==2 || number%oddnumber>0)
but i have a problem here which is how can i define the whole odd number without using cmath????
Explanation / Answer
please rate - thanks
#include <iostream>
using namespace std;
int main()
{int i,num,factors;
cout<<"Enter a number ";
cin>>num;
while (num<=0)
{cout<<"must be>0 ";
cin>>num;
}
factors=0;
for(i=2;i<=num/2;i++)
if(num%i==0)
factors++;
if(factors==0)
cout<<num<<" is prime ";
else
cout<<num<<" is not prime ";
system("pause");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.