wis男士面膜:C语言题目!!!!!

来源:百度文库 编辑:高校问答 时间:2024/04/30 03:56:38
C语言题目!!急~~~
题目:连续输进去一些数(遇到0退去),如输进去24,把它的个十位分开,加起来为6;
如输进去十39,它的个十位相加为12,然后继续把它的个十位分开,直到加起来为一个个位数为止
如:输进去
24
39
0
输出: (当输入0时,退去,而且在输出时,不输出0)
6
3

这道题目的英文是: Background

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 that digit is the digital root. 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 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 12 is not a single 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 will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.

Output

For each integer in the input, output its digital root on a separate line of the output.

Example

Input

24
39
0
Output

6
3
#define N 50
int ss(int num)
{
int sum=0,k=0;
while(num>=10)
{
sum=num;
k=0;
while(sum!=0)
{
k+=sum%10;
sum/=10;
}
num=k;
}
return num;
}

int main()
{
int a[N]={0},i=0;
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
if(a[i]==0)break;
a[i]=ss(a[i]);
}
for(i=0;a[i]!=0;i++)
printf("%d\n",a[i]);
}

这个程序在编译的时候会出现两个警告:
"scanf"undefined; assuming extern returning int
"printf"undefined; assuming extern returning int

该怎么修改啊?
谢谢回答

没有头文件 #include<stdio.h>

很简单啊