Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // write the prototype below
- int digitSum(int n);
- // complete the main function to read input, call functions, and display output
- int main(void) {
- int num = 0;
- scanf("%d", &num);
- int result = digitSum(num);
- printf("%d", result);
- return 0;
- }
- // complete the function below
- int digitSum(int n) {
- // base case
- if(n == 0){
- return 0;
- }
- // recursive step
- else {
- return n%10 + digitSum(n / 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement