Beecrowd 1176 Fibonacci Array Solution

Beecrowd 1176 Fibonacci Array Question

Beecrowd 1176 Fibonacci Array Solution.Understanding Fibonacci Sequences: Before we dive into solving the problem, it is important to understand what Fibonacci sequences are. Fibonacci sequences are a series of numbers in which each number is the sum of the two preceding numbers. The sequence starts with 0 and 1, and the next number in the sequence is the sum of the two preceding numbers. For example, the first 10 numbers in the Fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.

Solving the URI 1176 Fibonacci Array Problem: To solve the URI 1176 Fibonacci Array problem, we need to first generate a Fibonacci sequence up to a given number. Once we have the sequence, we can calculate the sum of all even numbers in the sequence.

#include <stdio.h>

int main() {

   int i,j,a,d;
   long long int arr[61];
   arr[0]=0;
   arr[1]=1;
   for(i=2;i<61;i++)
       arr[i]=arr[i-1]+arr[i-2];
       scanf("%d",&a);
       for(j=0;j<a;j++){
           scanf("%d",&d);
           printf("Fib(%d) = %lld\n",d,arr[d]);
       }


    return 0;
}
#include <iostream>
using namespace std;

int main() {
    int i, j, a, d;
    long long int arr[61];
    arr[0] = 0;
    arr[1] = 1;

    for (i = 2; i < 61; i++)
        arr[i] = arr[i - 1] + arr[i - 2];

    cin >> a;

    for (j = 0; j < a; j++) {
        cin >> d;
        cout << "Fib(" << d << ") = " << arr[d] << endl;
    }

    return 0;
}

Previous problem: Even Square Problems Solution/Beecrowd 1073

1 thought on “Beecrowd 1176 Fibonacci Array Solution”

Leave a Comment