> 其他 >
从键盘上输入任意一个整数x,编程计算x的每一位数字相加之和,用C语言编写,下面我编写的程序哪错了
例如,输入x为1234,则分离出1,2,3,4四个数字,然后计算1+2+3+4=10,并输出10,
#include
#include
void main()
{
\x09int n=0;
\x09while("getchar()"!="\n")
\x09{
\x09\x09n+=getchar();
\x09\x09
\x09}
\x09printf("%d",n);
\x09system("pause");
}
人气:210 ℃ 时间:2020-05-04 12:35:26
解答
ch-'0'是什么意思ch为char类型,假设是'6'<注意单引号,读作“字符常量六”>ch-'0'等于6,也就是通常说的六<6>.
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版