0

int foo(int n,int r){ if(n>0) return (n%r+foo(n/r,r)); else return 0; } int main (){ printf("%d",foo(345,10)); }

Why is output 12??

9th May 2020, 8:05 AM
Karan Dewangan
Karan Dewangan - avatar
1 Réponse
+ 2
n%r will give 5 and then func will run again with 34 and 10 Now n%r will give 4 and then func will run again with 3 and 10 ,now n%r will give 3 and func will run again with 0 and 10 but now since n is equal to 0 ,0 will be returned and func stops executing So we have 5+4+3 now
9th May 2020, 8:12 AM
Abhay
Abhay - avatar