Write a console program that asks the user to enter an integer greater than 1. The program determines if the number entered is prime and writes a message to standard output stream stating whether the number is prime or not. For example, if the user enters 42, the program displays "42 is not prime." If the user enters 47, the program displays "47 is prime." Develop 8 test cases and verify that your program runs correctly for them. The test cases should contain some prime numbers as well as non-prime values. Include test cases that try to break your program so that you are sure you have implemented the code correctly. Include the 8 test cases within a multi-line comment near the top of your source code file. Make sure the comment is nicely organized and easy to read and understand. |
Write a console program that reads a positive integer entered by the user. The program computes and displays all the prime numbers between 2 and the number entered. To solve this problem, you need to nest an inner loop within an outer loop. |
Write a console program that asks the user to enter a positive integer greater than 1. The program computes the prime factors of the number and prints them. For example, if the user enters 100, the program displays 2 2 5 5. |
|
|
thanks, but I have never used count before, and my professor has not talked about it |
count
in the example above is an integer variable. count++
uses the increment operator ++
to add 1 to count.
|
|
Do I have to do anything special when usuing bool
bool Primenumber(int);
@yulingo: your example is flawed, it consider all the numbers as prime |
isPrime = true;
should be false on line 8.
|
|
for( int i = 1; i <= n; i++ )
to for( int i = 2; i < n; ++i );
since you don't know about square roots you said earlier. n % i
I don't want to seem harsh or anything but I think you need to read up a little bit more on loops and operators a little bit more.