Jump to content

Featured Replies

Posted

Write a program that calculates the Nth Fibonacci number. The Fibonacci sequence is defined as follows:

  • F(0) = 0
  • F(1) = 1
  • F(n) = F(n-1) + F(n-2) for n > 1

Requirements:

  1. Allow the user to input the value of N.
  2. Implement the program in two ways:
    • Using recursion.
    • Using iteration (for efficiency with larger N).
  3. Optimize the recursive solution with memoization or dynamic programming to handle larger values of N.

Bonus:

  • Print the time taken by both methods to compute the result for comparison.

Example Output:

For N = 10, the result should be 55.

  • Views 134
  • Created
  • Last Reply

Create an account or sign in to comment

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.