Lesson 9 of 24

Recursion

10 min 30 XP

Recursion-এ function ছোট input-এ নিজেকেই call করে যতক্ষণ না base case থামায়। Tower of Hanoi ক্লাসিক উদাহরণ: n-টি disk-এর জন্য 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.