Example C program to sum up all individual digits of a given number:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <stdio.h> int main() { int n, sum = 0, rem; printf("Please enter an integer\n"); scanf("%d",&n); while(n != 0) { rem = n % 10; sum = sum + rem; n = n / 10; } printf("Sum of all individual digits of an entered number is %d\n",sum); return 0; } |