Question: Programming in C Sum of Digits Write a program sumOfDigits.c that reads an integer from the user and computes the sum of all the decimal
Programming in C
Sum of Digits Write a program sumOfDigits.c that reads an integer from the user and computes the sum of all the decimal digits of that integer. Suppose that the user enters a decimal integer 123. Then the sum of all its decimal digits is 1+2+3=6. You may assume that the integer entered is between 0 and 9999. Your program should also ask the user to enter the predicted sum of digits. It should then output your computed sum and the user score. The user scores O if the predicted sum of digits is incorrect and 1 if the predicted sum is correct. 123 A sample run of your program: Enter an integer between 0 and 9999: Guess the sum of its digits: 7 Your score is: 0 To obtain the first digit of the number, divide the number by 10, and capture the remainder. In the above example, divide 123 by 10 to get 12 and capture the remainder 3. To obtain the second digit, divide the number again by 10, and capture the new remainder, and so on. In the above example, divide the number 12 by 10 to get 1 and capture the new remainder, 2 and so on. This process ends when the number is smaller than 10. In the above example, 1 is smaller than 10 and 1 is the last new remainder
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
