"Solving"-avionics OJ1013 Digital Roots

Source: Internet
Author: User

Problem Description the digital root of a positive integer is found by
Summing the digits of the integer. If The resulting value is a single
Digit then, digit is the digital root. If the resulting value
Contains or more digits, those digits is summed and the process
is repeated. This is continued as long as necessary to obtain a single
Digit.

For example, consider the positive integer 24. Adding the 2 and the 4
Yields a value of 6. Since 6 is a single digit, 6 is the digital root
of 24. Now consider the positive integer 39. Adding the 3 and the 9
Yields 12. Since Digit, the process must be
Repeated. Adding the 1 and the 2 Yeilds 3, a single digit and also the
Digital root of 39.

Input the input file would contain a list of positive integers, one per
Line. The end of the input would be indicated by an integer value of
Zero.

Output for each integer in the input, output it digital root on a
Separate line of the output.

Sample Input

24 39 0

Sample Output

6 3

The topic examines the nine-odd theorem.

#include <stdio.h>#include <string.h>Charn[10001];intAdd_digital (Const Char* Str) {intresult =0;Char* pointer = (Char*) str; while(*pointer) {result + = *pointer- -;    pointer++; }returnResult;}intMain () { while(scanf('%s ', N)) {if(!strcmp(N,"0")) Break;intsum = Add_digital (n);printf("%d\n", (Sum-1)%9+1); }return 0;}

"Solving"-avionics OJ1013 Digital Roots

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.