C语言输入一个任意数求各位数的和
int main(void)
{
int x, r, s = 0;
scanf("%d", &x);
while (x>0)
{
r = x % 10;
s = s + r;
x = x / 10;
}
printf("%d", s);
getchar();
system("pause");
return 0;
}
int main(void)
{
int x, r, s = 0;
scanf("%d", &x);
while (x>0)
{
r = x % 10;
s = s + r;
x = x / 10;
}
printf("%d", s);
getchar();
system("pause");
return 0;
}