please anyone tell about this code, i cant understand ( rekursif ) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

please anyone tell about this code, i cant understand ( rekursif )

#include <iostream> void cetak(int n){ if(n == 0) return; cetak(n-1); std::cout << n << " "; } int main(){ cetak(10); return 0; }

5th Jun 2020, 11:43 PM
Salman Al-Farisy
Salman Al-Farisy - avatar
1 Answer
+ 2
cetak(10) -> 10==0? no, then << 1 cetak(10-1)-> 9==0? no, then << 2 cetak(9-1)-> 8==0? no, then << 3 cetak(8-1)-> 7==0? no, then << 4 cetak(7-1)-> 6==0? no, then << 5 cetak(6-1)-> 5==0? no, then << 6 cetak(5-1)-> 4==0? no, then << 7 cetak(4-1)-> 3==0? no, then << 8 cetak(3-1)-> 2==0? no, then << 9 cetak(2-1)-> 1==0? no, then << 10 cetak(1-1)-> 0==0? yes, return; while not exit from the last recursive function, we will not go forward.
6th Jun 2020, 2:08 AM
Роман Львов
Роман Львов - avatar