Skip to main content

Sum of digits in a number

#include <stdio.h> #include <math.h> int main() { int n, sum = 0, rem; printf("Enter a number : "); scanf("%d" , &n ); while( n > 0 ) { rem = n % 10; sum = sum + rem; n = n / 10; } printf("\n\nThe sum is : %d\n\n", sum); }




Comments