2025-03-06 23:47:59 +08:00

22 lines
413 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
功能从键盘输入一位整数i计算其各位数字之和。比如输入整数
31421则打印结果为11。使用while循环
--------------------------------------------------------*/
#include<stdio.h>
main()
{
int i,sum=0,a;
scanf("%d",&i);
/**********Program**********/
while(i){
sum += i%10;
i/=10;
}
/********** End **********/
printf("%d\n",sum);
}