acm 1115题

来源:百度知道 编辑:UC知道 时间:2024/05/30 05:43:22
acm 1115题 就是求Digital Roots这么一个数, 例如39,那么Digital Roots就是3+9=12,1+2=3 Digital Roots是3
我的程序是:
#include<stdio.h>
int main()
{
int b;
long a;
while(1)
{
scnaf("%d",&a);
if(a==0) break;
b=a%9;
if(b==0) b=9;
printf("%d",b);
}
}
不知道为什么总是错的

#include<stdio.h>
int main()
{
int b;
long a;
while(1)
{
scanf("%ld",&a); /*要用%ld*/
if(a==0) break;
b=a%9;
if(b==0) b=9;
printf("%d\n",b);
}
}

printf("%d\n",b);
输出的时候要有换行