HW10
COP-3223H
Setup
See HW7's Setup for how to prepare for performing and submitting your homework.
Homework file names
- hw10-1.c
- hw10-2.c
Questions
(
hw10-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"); } }- (
hw10-2.c) write a program that uses only the constructs shown in class so far (single-branch if 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.
Submission
See HW7's Submission instructions for adding, committing, and pushing your homework to the assignments' repo.
Self-check
See HW7's Self-check for instructions on checking what you have submitted to the remote grading repository.