#include <stdio.h>
#include <math.h>
int findSumOfDigitsOfNumber(int number);
int main() {
int number;
scanf("%d", &number);
printf("Sum of the digits of %d is = %d ", number, findSumOfDigitsOfNumber(number));
return 0;
}
int findSumOfDigitsOfNumber(int number) {
int sum = 0, digit = 0, tempNumber = number;
while(tempNumber != 0) {
digit = tempNumber%10;
printf("Current digit is: %d \n", digit);
sum = sum + digit;
tempNumber/=10;
}
return sum;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.