PTA 7-7 beg integer digits and the sum of the digits (15 points)

PTA 7-7 beg integer digits and the sum of the digits (15 points)

#include<stdio.h>
int main()
{
    unsigned long int a;
    int b, c,d;
    int sum = 0;
    int count = 1;
    scanf("%ld", &a);
    c = a;
    while (c=c/10)
    {
        count++;
    }
    b = count;
    while(count--)
    {
        d = a % 10;
        sum += d;
        a = a / 10;
    }
    printf("%d %d", b, sum);
}

Guess you like

Origin blog.51cto.com/14737345/2479858