UP | HOME

HW7
COP-3223H

Submit this project via git (not webcourses) using the Uploading homework to git documentation.

  1. (hw7-1.c) Hand-copy yourself without copy-and-paste the following program into a file on eustis and compile and run it.

    #include <stdio.h>
    
    int main(int argc, char **argv) {
      int num;
    
      // read an integer from the user
      scanf("%d", &num);
    
      // print the number from the user
      printf("%d\n", num);
    
      int x;
    
      // multiply by nine
      x = num * 9;
    
      printf("%d\n", x);
    
      // get the ones, tens, and hundreds digits
      int ones_digit = x % 10;
      int tens_digit = (x / 10) % 10;
      int hundreds_digit = (x / 10 / 10) % 10;
    
      // sum the first three digits
      int sum = ones_digit + tens_digit + hundreds_digit;
    
      // print the sum
      printf("%d\n", sum);
    
      if (sum != 9) {
        printf("we need to continue summing the results digits\n");
      }
    }
    
  2. (hw7-2.c) write a program that uses only the constructs shown in class so far (if statements (not if-then-else statements) comparison operators, and printf/scanf) to write a program that inputs two integers and checks whether both of the inputs guessed the correct number 5. Print "both right\n" once when both inputs guess the right number, otherwise print "first input wrong\n" and/or "second input wrong\n" if one or both of the numbers are wrong. See Game: Guessing game as a starting point for this program.
  3. In this exercise, you will create three programs that do the same thing:

    • Input: one integer x
    • Output:
      • "yes\n" when x is both even and positive
      • "no\n" otherwise

    a. (hw7-3a.c) For the first program, use a single if-then-else statement and a Boolean operation to implement the program.

    b. (hw7-3b.c) For the second program, use only two if statements (not if-then-else) and Boolean operations to implementation the program.

    c. (hw7-3c.c) For the third program, use only if statements (not if-then-else) and no Boolean operations. It is possible to use four if statements (with nesting).

Author: Paul Gazzillo

Created: 2026-07-26 Sun 20:06