0
Recursion
A function which can call by itself. long fact(int); main () { int n; long f; cout<<"Enter n"; cin>>n; f=fact (n); cout <<fact (n); return0; } long factorial(int n) { if (n==1||n==0) { return 1; } else { return n * factorial(n-1); } } //output: Enter n 5 fact (5) 120
8 odpowiedzi
+ 3
@Setiawan I couldn't find anything on there describing that posting the code on the question is bad.
Although, I'm not sure what the question is, which I guess was your point xD.
😜
@Harini
You have 'long f' yet you never use it. You assign f to the value of factorial(n) (which is wrong because you wrote fact, when the function is named factorial. So the output is really compilation error) but never used the long. When you printed out you just called the factorial function again.
Fix:
f = factorial(n);
cout<<f;
Or don't use the long at all.
+ 3
@Setiawan Ah, yea idk why they wouldn't use code playground. I'd assume it's just copy pasted then, from which they would not be learning from. 😶
Idk though.
+ 2
@Rrestoring faith
it was not question, he/she just post a code.
why he/she didn't use codeplayground to test his/her code?
did he/she seriously learning ?
+ 1
c'mon why people post code on question.
write them on code playground!
https://www.sololearn.com/discuss/321242/?ref=app
+ 1
@Setiawan
I feel the same as you. I used to advise them use code playground.
But many of them are just do not like to share it from code playground, maybe they ain't sure code can be share from there.
+ 1
@Calvin
Maybe we should give feedback to Sololearn to give faq page on how using Sololearn feature. So we don't have to explain everytime to many duplicated question.
+ 1
@Setiawan
We could try to inform SL.
Another reason why they are not awake that the code can be inserted to post here is the function of "+ Insert..." selection is too vague.(in fact, it took me sometime to realise I can use it to insert code)
Since it only contains 2 selections "Insert Code" and "Insert Post", why don't directly show these 2 selection beside the POST button instead?
0
@Calvin
i agree.