Consider the following recursive implementation to find the sum of digits of number:
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
if(n == 0)
return 0;
return _________;
}
int main()
{
int n = 1201;
int ans = recursive_sum_of_digits(n);
printf("%d",ans);
return 0;
}
Which of the following lines should be inserted to complete the above code?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
if(n == 0)
return 0;
return _________;
}
int main()
{
int n = 1201;
int ans = recursive_sum_of_digits(n);
printf("%d",ans);
return 0;
}
A. (n / 10) + recursive_sum_of_digits(n % 10)
B. (n) + recursive_sum_of_digits(n % 10)
C. (n % 10) + recursive_sum_of_digits(n / 10)
D. (n % 10) + recursive_sum_of_digits(n % 10)
Answer: Option C
Join The Discussion