What is the time complexity of the following recursive implementation to find the sum of digits of a number n?
Posted: Wed Jul 13, 2022 7:39 pm
#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) O(n)
b) O(1)
c) O(len(n)), where len(n) is the number of digits in n
d) O(1/2)
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) O(n)
b) O(1)
c) O(len(n)), where len(n) is the number of digits in n
d) O(1/2)