Question: create a C program and save it as integerPropsYourInitials.c in your cop 2 2 2 0 folder. ( Replace YourInitials with your own initials. )

create a C program and save it as integerPropsYourInitials.c in
your cop2220 folder. (Replace YourInitials with your own initials.)
The program is designed to determine which integers from 2 to a given
integer are prime or perfect. The program will be designed so that it
contains functions that you will write. ALL function bodies are to be
written BELOW the main function.
The function prototypes that you type just above the header of the
main function are: (Note that you will be writing the code for these
functions below the main.)
int getUpperBound();
int isPrime(int);
int isPerfect(int);
The algorithm for the main function follows: (Pay attention to
indentation in the algorithm.)
Declare an integer variable named upperBound.
Call a function (that YOU will write later) named getUpperBound
that takes no parameters but returns an integer that you assign
to the upperBound variable.
Declare a variable named num.
Write a for loop that starts num at 2 and goes up to (and
including) the upperBound. Increment num by 1. In the loop do:
Use a function (that you will write) named isPrime to see
if num is a prime number. The function should be passed
the variable num. If isPrime returns 1, then print the
number along with a message that says that the number is a
prime number.
Integer Properties
Page 2
Else, use a function (that you will write) named isPerfect
to see if num is a perfect number. The function should be
passed the variable num. If isPerfect returns 1, then
print the number along with a message that says that the
number is a perfect number.
The algorithm for the getUpperBound function follows:
Declare an integer variable named upper.
Do
Ask for an integer bigger than or equal to 2 and less than
or equal to 1000 and store that integer in the upper
variable.
If upper is less than 2 or bigger than 1000, print a
message stating that the integer must be from 2 to 1000.
while upper is less than 2 or bigger than 1000.
Return upper.
The algorithm for the isPrime function follows:
A prime number is an integer bigger than 1 that only has 1 and
itself as divisors.
As shown in the prototype near the top of this document, this
function takes one parameter that I will refer to as the
parameter. You must give your parameter an actual name (NOT
parameter).
See if the parameter is less than or equal to 1. If it is,
return 0.
See if the parameter is equal to 2. If it is, return 1.
Declare an integer variable named divisor.
Start a for loop by setting divisor equal to 2 and going up to,
but not including, the parameter. Increment the divisor by 1.
Inside the loop do:
See if the parameter is divisible by the divisor. (Note:
an integer m is divisible by another integer n if m mod n
is 0. That is, the remainder upon division of m by n is
0.) If it is return 0.
Outside and below the loop, return 1.
The algorithm for the isPerfect function follows:
A perfect number is an integer that is equal to the sum of its
divisors excluding the number itself. For example: 6 is perfect
because 1+2+3=6.28 is perfect because it is equal to 1+
2+4+7+14.
Integer Properties
Page 3
As shown in the prototype near the top of this document, this
function takes one parameter that I will refer to as the
parameter. You must give your parameter an actual name (NOT
parameter).
See if the parameter is less than or equal to 1. If it is,
return 0.
Declare an integer variable named total and set it to 1.
Declare an integer variable named divisor.
Start a for loop by setting divisor equal to 2 and going up to,
but not including, the parameter. Increment the divisor by 1.
Inside the loop do:
See if the parameter is divisible by the divisor. If it
is, add the divisor to the total.
Outside and below the loop, check to see if the total is equal
to the parameter. If it is, return 1.
[Else] Return 0.
If you test your program by entering 30 when you are asked for an
integer, you should see output like the following:
2 is prime.
3 is prime.
5 is prime.
6 is perfect.
7 is prime.
11 is prime.
13 is prime.
17 is prime.
19 is prime.
23 is prime.
28 is perfect.
29 is prime.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!