Suppose you are given a positive integer. You can add individual digits of this number to get another integer. Now apply the same procedure to the new integer. If we repeat this procedure, eventually...



Suppose you are given a positive integer. You can add individual digits of this number


to get another integer. Now apply the same procedure to the new integer. If we repeat


this procedure, eventually we will end up with a single digit. Here is an example:


7391928 = 7 + 3 + 9 + 1 + 9 + 2 + 8 = 39


39 = 3 + 9 = 12


12 = 1 + 2 = 3.


Write a program that reads a positive integer from the user and displays the single digit


as obtained by the above procedure. For the example, the output should be 3.


Your program should detect negative input as an error and terminate after displaying an


appropriate error message.



May 26, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here