#include
main()
{
int a,b,c,k,s1,s2;
printf("输入一个三位数:\n");
scanf("%d",&k);
a=k/100;
b=k/10%10;
c=k%10;
s1=a+b+c;
s2=a*a+b*b+c*c;
printf("该三位数各位数字之和为%d;\n",s1);
printf("该三位数各位数字平方和为%d\n",s2);
}
#include
int main()
{
int n,sum1,sum2,one;
printf("input n:");
scanf("%d" , &n );
sum1=sum2=0;
while ( n ) //当n不为0时循环
{
one=n%10 ; //取一位
n/=10; //n缩小10倍,最后归0
sum1 += one ;
sum2 += one *one ;
}
print("sum1=%d\n",sum1);
print("sum2=%d\n",sum2);
return 0;
}
上面那位好像是对的,我就不用说了