sum of digit of a number in c

#include<stdio.h>
int main()
{
    int digit, temp, output = 0;
    printf("input : ");
    scanf("%d", &temp);
    while(temp>0){
        digit = temp%10;
        output = output + digit;
        temp = temp/10;
    }
    printf("output : %d", output);
}



OUTPUT :

testcase 1 - input : 11






testcase 2 - input : 123




Comments

Popular posts from this blog

JWT auth