Question
Please write a c++ code for my pseudo code. I am take a class that is teaching me flow charts and pseudocode and I would
Please write a c++ code for my pseudo code. I am take a class that is teaching me flow charts and pseudocode and I would like to see the actual code so that I can start preparing myself for next semesters classes. Here is the pseudo code:
// main module
Module main()
// Local variables
Declare Integer number
// Get number
Call getNumber(number)
// Show if number is prime
Call showPrime(number)
End Module
// The getNumber module gets an integer
Module getNumber(Integer Ref inputAnswer)
Display Enter an integer:
Input inputAnswer
End Module
// The showPrime module shows if number is a prime
Module showPrime(Integer number)
If IsPrime(number) Then
Display The number is a prime.
Else
Display The number is not prime.
End If
End Module
// The IsPrime function returns True if number is prime, False if odd.
Function Boolean IsPrime(Integer number)
Declare Boolean status
Declare Integer count, half
Set status = False
Set half = number / 2
For count = 2 to half
If number MOD count == 0
Set status = True
End If
End For
Return status
End Function
Out put should look like below:
Enter a candidate prime number: 1 1 is a prime number Enter a candidate prime number: 2 2 is a prime number Enter a candidate prime number: 3 3 is a prime number Enter a candidate prime number: 4 4 is NOT a prime number Enter a candidate prime number: 5 5 is a prime number Enter a candidate prime number: 6 6 is NOT a prime number Enter a candidate prime number: 7 7 is a prime number Enter a candidate prime number: 8 8 is NOT a prime number Enter a candidate prime number: 9 9 is NOT a prime number Enter a candidate prime number: 10 10 is NOT a prime number Enter a candidate prime number: 11 11 is a prime number Enter a candidate prime number: 12 12 is NOT a prime number Enter a candidate prime number: 13 13 is a prime number Enter a candidate prime number: 22 22 is NOT a prime number Enter a candidate prime number: 23 23 is a prime number Enter a candidate prime number: 27 27 is NOT a prime number Enter a candidate prime number: 29 29 is a prime number Enter a candidate prime number:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started