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.