Write a C/C++ program which consists of a user-define function Prime. This function will take a numb

 Dont Buy Textbooks. Rent 'EM Save 60-80%



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


FirstPrevious12NextEnd

More Related Questions and Answers ...
  • C dac courses in hyderabad.its cost its detai..
  • Does defendant kenneth c dugan, have a crimin..
  • How can I get Borland C++ to output a string ..
  • How do I use cout an cin in a visual C++ 2005..
  • Help for computer c++ project banking?
  • C++ Have problem when im executing my code (M..
  • Please help!!! C++ user defined funtions?
  • Does anyone know some good colleges/universit..
  • C++..program runs fine but with errors in the..
  • How to write pseudo code in c++ program. what..
  • Urgent C++ Help?
  • Beginner C++ Help?
  • Help with C++ Program ?
  • What exactly is wrong with this C++ code.?
  • Convert C++ to C - Hanoi Tower?
  • C++ Help... I cant figure this one out.. Plea..
  • C++ HELP, I can get the program running, but ..
  • My c++ program is a basic one but i get this ..
  • Need some C++ help?

  • The information post by website user , we not guarantee correctness.

    

    Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes