对于给定的正整数N,求它的位数及其各位数字之和。
输入格式:
输入在一行中给出一个不超过109的正整数N。
输出格式:
在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。
输入样例:
321
输出样例:
3 6
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n=0,sum=0,i=0;
scanf("%d",&n);
while(n!=0)
{
sum+=n%10;
i++;
n/=10;
}
printf("%d %d",i,sum);
return 0;
}