Write a C/C++ program which consists of a user-define function Prime. This function will take a numb
Write a C/C++ program which consists of a user-define function Prime. This function will take a number and check that the number is prime or not if the number is prime Display The number is Prime other wise display The number is not PrimeCall this function in main program.
Write a C/C++ program which consists of a user-define function Prime. This function will take a number and chec++ template
#include <iostream>
// The following function works on positive numbers only
bool Prime(int number);
int main( )
{
int number = 0;
cout << "Enter a number: ";
cin >> number;
if(Prime(number))
cout << "The number is prime" << endl;
else
cout << "The number is NOT prime" << endl;
return 0;
}
bool Prime(int number)
{
for(int i = 2; i < number - 1; i++)
{
if((number % i) == 0)
return false;
}
return true;
}
Write a C/C++ program which consists of a user-define function Prime. This function will take a number and chemicrosoft visual c++
Don't post the question from your assignment to Internet; try to use your own imagination and skills you learnt from lectures; rather these assignments are brain teasers to make you ready for exams.|||First thing you need to do is set a cin>> statement for the user to enter a number. Then have the an if-then statement that checks the number against the formula for determining if a number is prime (I dont remember if off the top of my head but its something like a number thats only divisable by itself). Then you can set your cout<< after the if as "The number",x,"is prime." and then for the else cout<< "The number",x,"is not prime." Should work out fine. No need to make it more complicated than it needs to be.|||The code given by Silver is pretty good. I am only suggesting minor improvements to the same code
More Related Questions and Answers ...
The information post by website user , we not guarantee correctness.
Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes
