Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedProgramming 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago