Lesson 9 of 24

Recursion

10 min 30 XP

Recursion లో function base case ఆపే వరకు చిన్న 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.