123 = 6

 /* here % is ggiving remainder and / gives us quotient

*/


#include <stdio.h>



int main (){

    int num , rem=0, sum=0;

    printf("Enter the number that you want to add digits \n");

    scanf("%d", & num);

    while(num>0){

        rem=num % 10;

        sum = rem+sum;

        num = num/10;

    }

printf("sum of digit is %d ", sum);

return 0 ;

}

Comments

Popular posts from this blog

Factors : using C

Cross shaped pattern

Factorial ! calculation