什么是“Digital Roots"?
来源:互联网 发布:黑人歧视黄种人知乎 编辑:程序博客网 时间:2024/05/16 17:35
/*
*Digital Roots
*
*Background
*The digital root of a positive integer is found by summing the digits of the int
*eger. If the resulting value is a single digit then that digit is the digital ro
*ot. If the resulting value contains two or more digits, those digits are 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 v
*alue 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 12 is not a sin
*gle digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a sing
*le digit and also the digital root of 39.
*/
#include<stdio.h>
int
zhou (int n)
{
if (n < 10) /*如果n小于10了,也就得出计算结果了*/
return n;
else
return zhou (sep (n));
}
int
sep (int n) /*返回n各位数之和*/
{
int sum = 0;
while (n) /*sum记录一个数的各位数之和*/
{
sum += n % 10;
n = n / 10;
}
return sum;
}
int
main ()
{
int n;
printf ("Enter an Integer number:");
scanf ("%d", &n);
printf ("The digit root of %d is %d\n", n, zhou (n));
return 0;
}
0 0
- 什么是“Digital Roots"?
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- GB 18030
- 第六章 电磁新理论
- Linux中大括号扩展参数的使用方法
- js数组的sort排序详解
- 解决MFC中CListCtrl(virtual)控件闪烁问题
- 什么是“Digital Roots"?
- linux下安装java环境
- error while loading shared libraries
- spring+hibernate实现分库分表操作
- C++设计模式之命令模式
- 导入excel格式的文件并写入到数据库中
- Flex之旅:第二部分:容器与布局(7)---使用IdeferredInstance 创建模板,实现组件的延迟加载
- 计算几何 模板
- 测试环境上错误排查