Assignment Instructions

  1. Edit, compile, and run the following program on the UH UNIX shell:
    1. Write a program with a main() function and the following five (5) functions definitions (and corresponding function prototypes and function calls).
      1. You will be inputting numbers, so at the top of your program, include the getdouble.h header file: #include "getdouble.h"
      2. Ask the user to "Enter two positive integers, separated by a space, the first smaller than the second".
      3. Use function getdouble() twice to get the two integers from the user. For example:
        int first = (int)getdouble();
        int last = (int)getdouble();
      4. Do NOT use function scanf(), because it is easy for someone to crash your program with this function.
      5. Do some error checking on the input.
      6. Use recursion to display the integers from the first integer to the second integer. The return type should be "void". Use printf() statements in your function to display the integers.
      7. Use recursion to add the sum of the integers from the first integer to the second integer. The return type should be "int". Display the result in main().
      8. Use recursion to multiply the product of the integers from the first integer to the second integer. The return type should be "int".
      9. Use recursion to calculate the first integer to the power of the second integer. The return type should be "int". Display the result in main(). Please do NOT use the C library pow() function.
      10. Use recursion to calculate the GCD (greatest common divisor) of the first integer and the second integer. The GCD is the largest integer that divides both x and y.
        The base case is: if y is equal to 0, then the return value is x.
        The recursive case is: The return value is gcd(y, x%y).
        The return type should be "int".
        Display the result in main().
    2. Email your makefile and C program to the instructor, or show it to the instructor in class.
  2. For the submission guidelines and the grading guidelines, see the syllabus.

Example I/O

Enter two positive integers, separated by a space, the first smaller than the second: 5 1
ERROR: 5 is not smaller than 1

Enter two positive integers, separated by a space, the first smaller than the second: -1 5
ERROR: both numbers must be positive

Enter two positive integers, separated by a space, the first smaller than the second: 1 5
Counting from 1 to 5: 1 2 3 4 5 
The sum of 1 to 5 = 15
The product of 1 to 5 = 120
1 to power of 5 = 1
The GCD of 1 and 5 = 1

Counting from 2 to 6: 2 3 4 5 6 
The sum of 2 to 6 = 20
The product of 2 to 6 = 720
2 to power of 6 = 64
The GCD of 2 and 6 = 2

Counting from 6 to 9: 6 7 8 9 
The sum of 6 to 9 = 30
The product of 6 to 9 = 3024
6 to power of 9 = 10077696
The GCD of 6 and 9 = 3

Click to validate the HTML code

Click to validate the CSS code