+ 1
Cprogram-add all num using recursion:67=6+7=output=1+3=4. The code output is correct!! this recursion method is correct or not??
#include <stdio.h> int jansi(int a) { if((a/10)!=0) { return (a%10)+jansi(a/10); } else { return a; } } int main() { int a,value; scanf("%d",&a); value=jansi(a); while( value/10!=0) { value=jansi(value); } printf("%d",value); return 0; }
6 Antworten
0
Until become single digit number.. Yes thats what you trying.. Is not it..?
67=> 6+7=13=>1+3=4.
+ 1
You can check in the playground by saving code and running it..?
Do you have any difficulty in that..?
Just try to remove warning....
+ 1
Ok thank you 🔥🔥
+ 1
The code output is correct!! But,this recursion method is correct or not?? because,calling the function is continuing till the value becomes 1 digit number!!
Check and tell me!!
+ 1
Yes
0
Yes, it works well. Just remove the two unused variables b and sum in jansi() in order to be compilable in SoloLearn.