Masala

1. Summation:

  • Masala: 1 dan n gacha bo'lgan barcha sonlarning yig'indisini hisoblang.

  • Ko'rsatma: Ushbu masalani ikkala iterativ va recursive usulda yeching.

  • Misol: n = 5, javob: 1 + 2 + 3 + 4 + 5 = 15.

2. Fibonacci:

  • Masala: n-o'rindagi Fibonacci sonini hisoblang.

  • Ko'rsatma: Fibonacci qatorini iterativ va recursive usullarda hosil qiling.

  • Misol: n = 6, Fibonacci soni: 8 (qator: 0, 1, 1, 2, 3, 5, 8).

3. Array Reverse:

  • Masala: Berilgan massivni teskari qilib chiqaring.

  • Ko'rsatma: Massivni iterativ va recursive usullarda teskari o'giring.

  • Misol: [1, 2, 3, 4, 5] -> [5, 4, 3, 2, 1].

4. Power Calculation:

  • Masala: a sonining n-darajasini hisoblang (a^n).

  • Ko'rsatma: Ikkala yondashuvda (iterative va recursive) daraja hisoblash funksiyasini yarating.

  • Misol: a = 2, n = 3, javob: 8.

5. Greatest Common Divisor (GCD):

  • Masala: Ikki sonning eng katta umumiy bo'luvchisini (GCD) toping.

  • Ko'rsatma: GCD'ni iterativ va recursive usullarda hisoblang.

  • Misol: GCD(48, 18) = 6.

6. Palindrome Check:

  • Masala: Berilgan so'z palindrome (orqaga o'qiganda bir xil) ekanligini tekshiring.

  • Ko'rsatma: So'zni iterativ va recursive yondashuvda tekshiring.

  • Misol: "radar" palindrome, "hello" palindrome emas.

7. Factorial:

  • Masala: Berilgan sonning faktorialini hisoblang.

  • Ko'rsatma: Faktorialni ikkala usulda hisoblang (iterativ va recursive).

  • Misol: 5! = 120.

8. Sum of Digits:

  • Masala: Berilgan sonning barcha raqamlari yig'indisini toping.

  • Ko'rsatma: Raqamlar yig'indisini iterativ va recursive usullarda toping.

  • Misol: 1234 -> 1 + 2 + 3 + 4 = 10.

9. Exponentiation by Squaring:

  • Masala: Berilgan sonning n-darajasini tezkor exponentiation usuli yordamida hisoblang.

  • Ko'rsatma: Exponentiation by Squaring algoritmini iterativ va recursive usullarda qo'llang.

  • Misol: 2^10 = 1024.

10. Binary Search:

  • Masala: Tartiblangan massivda ma'lum bir qiymatni izlang.

  • Ko'rsatma: Binary search algoritmini iterativ va recursive yondashuvlar bilan bajaring.

  • Misol: [1, 3, 5, 7, 9], qidirilayotgan son: 5, javob: 2 (indeks).

Har bir masalani yechishda avval funksiyaning iterativ yechimini toping, so'ng recursive usulda qanday qilish mumkinligini o'rganing. Bu masalalar orqali iterative va recursive funksiyalarni qanday qo'llashni yaxshi o'rganasiz.

Last updated