Question: #include / / FORWARD DECLARATIONS int digitSum ( int number ) ; int main ( int argc, char * argv [ ] ) { int
#include
FORWARD DECLARATIONS
int digitSumint number;
int mainint argc, char argv
int num;
int sum;
Prompt for, and receive user input
printfEnter a number whose digits should be summed: ;
if scanfd &num
printfSorry you didn't enter a number.
;
return ;
Calculate the sum of the digits of the provided number
sum digitSumnum;
Print out the result.
printfThe sum of the digits of d is d
num, sum;
Return success
return ;
Calculate and return the sum of the digits of a given number.
@param number
The number whose digits are to be summed
@return
The sum of the number's digits
int digitSumint number
int digit;
int sumOfDigits ;
while number
Get the next digit
digit number ;
Add this digit to the sum
sumOfDigits sumOfDigits digit;
Prepare for next digit
number number ;
Give em the sum
return sumOfDigits;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
