Digital Roots数字根 12
2015-11-25 20:18
393 查看
Digital Roots数字根
Problem Description
The digital rootof a positive integer is found by summing the digits of the integer. If theresulting value is a single digit then that digit is the digital root. If theresulting value contains two or more digits,
those digits are summed and theprocess is repeated. This is continued as long as necessary to obtain a singledigit.
For example, consider the positive integer 24. Adding the 2 and the 4 yields avalue of 6. Since 6 is a single digit, 6 is the digital root of 24. Nowconsider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 isnot a single digit, the process
must be repeated. Adding the 1 and the 2 yeilds3, a single digit and also the digital root of 39.
一个正整数的数字根总结了该整数的位数找到。如果结果值是一位数字,然后该数字是数字根。如果结果值包含两个或多个数字,这些数字相加并重复该过程。这是,只要有必要继续获得单个数字。
例如,考虑的正整数24.添加的2和4产生的值为6。由于6是一位数字,6是24.数字根现在考虑正整数39.添加3和9的产量12.自12不是一个单独的数字,该过程必须重复。添加1和2 yeilds3,一个单一的数字,也为39的数字根。
Input
The input filewill contain a list of positive integers, one per line. The end of the inputwill be indicated by an integer value of zero.
输入文件将包含正整数,每行一个的列表。输入的结束将通过0整数值表示
Output
For each integerin the input, output its digital root on a separate line of the output.
对于输入,输出它的数字根对输出的一个单独的行每个整数。
Sample Input
24
39
0
Sample Output
6
3
代码如下:
Problem Description
The digital rootof a positive integer is found by summing the digits of the integer. If theresulting value is a single digit then that digit is the digital root. If theresulting value contains two or more digits,
those digits are summed and theprocess is repeated. This is continued as long as necessary to obtain a singledigit.
For example, consider the positive integer 24. Adding the 2 and the 4 yields avalue of 6. Since 6 is a single digit, 6 is the digital root of 24. Nowconsider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 isnot a single digit, the process
must be repeated. Adding the 1 and the 2 yeilds3, a single digit and also the digital root of 39.
一个正整数的数字根总结了该整数的位数找到。如果结果值是一位数字,然后该数字是数字根。如果结果值包含两个或多个数字,这些数字相加并重复该过程。这是,只要有必要继续获得单个数字。
例如,考虑的正整数24.添加的2和4产生的值为6。由于6是一位数字,6是24.数字根现在考虑正整数39.添加3和9的产量12.自12不是一个单独的数字,该过程必须重复。添加1和2 yeilds3,一个单一的数字,也为39的数字根。
Input
The input filewill contain a list of positive integers, one per line. The end of the inputwill be indicated by an integer value of zero.
输入文件将包含正整数,每行一个的列表。输入的结束将通过0整数值表示
Output
For each integerin the input, output its digital root on a separate line of the output.
对于输入,输出它的数字根对输出的一个单独的行每个整数。
Sample Input
24
39
0
Sample Output
6
3
代码如下:
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int divide(int b); void main(){ int a,temp; do{ scanf("%d",&a); temp=divide(a); if(temp>10){ temp=divide(temp); printf("%d的数字根是%d\n",a,temp); }else{ printf("%d的数字根是%d\n",a,temp); } }while(a!=0); } int divide(int b){ int m,n,sum; m=b%10; n=b/10%10; sum=m+n; return sum; }
相关文章推荐
- 带有N多BUG的小程序——贪吃蛇
- 拷贝文本文件的两种方式
- [Android]获取系统电话本实例
- 【iOS 开发】iOS 开发 简介 (IOS项目文件 | MVC 模式 | 事件响应机制 | Storyboard 控制界面 | 代码控制界面 | Retina 屏幕图片适配)
- css input[type=file] 样式美化,input上传按钮美化
- Java抽象类详解
- u Calculate e 11
- Java反射的基本操作
- Java中常用的正则表达式
- 第三方sdk接入
- C++11学习笔记(一)
- Java中常用的正则表达式
- LCA算法(一)
- Orcad下使用TCL脚本自动生成导线和网络标号
- Codeforces Round #278 (Div. 1) A. Fight the Monster( 暴力)
- 小议代码的巨量注释=>LTS
- FatMouse' Trade 10
- 学习日记--Android VideoView播放视频控制:开始、暂停、快进
- CSS属性选择器
- Blog follow/unfollow implementation