pc009.c (408B)
1 /* Sum of digit */ 2 3 #include <stdio.h> 4 int main() 5 { 6 int num, sumOfDigit = 0, temp; 7 printf("Enter the number : "); 8 if (scanf("%d", &num) != 1) 9 { 10 printf("\nOnly a number is allowed."); 11 return 1; 12 } 13 temp = num; 14 while (temp > 0) 15 { 16 sumOfDigit += temp % 10; 17 temp /= 10; 18 } 19 printf("\nSum of the digit %d : %d", num, sumOfDigit); 20 return 0; 21 }