7-28 求整数的位数及各位数字之和
1 #include <stdio.h> 2 3 int main(void) 4 { 5 int num; 6 int n, sum; 7 8 n = 0; 9 sum = 0; 10 scanf("%d", &num); 11 12 do 13 { 14 sum = sum + num % 10; 15 num = num / 10; 16 n++; 17 } while (num > 0); 18 19 printf("%d %d\n", n, sum); 20 return 0; 21 }