Lesson 9 of 24

Recursion

10 min 30 XP

Recursion: function தன்னைத்தானே சிறிய input-உடன் அழைக்கும். Base case நிறுத்தும். Tower of Hanoi recursion-ன் புகழ்பெற்ற உதாரணம்: n disks-க்கு 2ⁿ - 1 moves.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Challenge

+30 XP

long long fastPower(long long base, int exp) என்ற recursive function எழுதுங்கள்: exp இரட்டை எண் என்றால் half = fastPower(base, exp/2); return half * half. main()-ல் base, exp படித்து விடையை print செய்யுங்கள். Input: 2 40 → Output: 1099511627776

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.