#include
int main()
{
int n, sum=0, r, all = 1;
printf("请输入一个自然数:");
scanf("%d",&n);
r = n;
while(r>0)
{
sum += r % 10;
all *= r % 10;
r = r / 10;
}
printf("%d的各个位数之和为:%d\n", n, sum);
printf("%d的各个位数之乘积为:%d\n", n, all);
return 0;
}
int num = 123, sum = 0, multi = 1;
do{
sum += num % 10;
multi *= num % 10;//排除0的写法:multi *= (num % 10) == 0 ? 1: (num % 10);
num = num / 10;
}while(num > 0);