Lesson 9 of 24

Recursion

10 min 30 XP

Recursion-ൽ base case നിർത്തുന്നതുവരെ function ചെറിയ input-ൽ സ്വയം call ചെയ്യുന്നു. Tower of Hanoi ക്ലാസിക് ഉദാഹരണമാണ്: 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

Recursive long long fastPower(long long base, int exp) എഴുതൂ: exp ഇരട്ടയാണെങ്കിൽ half = fastPower(base, exp / 2) കണക്കാക്കി 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.