Write a c++ program that evaluates the first 50 numbers of the Fibonacci sequence and store the numbers in an array.
The c++ program asks the user for an input to enter a positive integer 'n' and display the nth fibonacci number "FibN" that is stored inside of the array
#include <iostream> using namespace std; int main() { unsigned long long int FibN[50]; FibN[0] = 0; FibN[1] = 1; for (int i = 2; i < 50; ++i) { FibN[i] = FibN[i-1] + FibN[i-2]; } cout << "First 50 fibonacci numbers are" << endl; for (int i = 0; i < 50; ++i) { cout << FibN[i] << endl; } cout << "Enter a positive integer: "; int n; cin >> n; cout << "Fibonacci of " << n << " is " << FibN[n-1] << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.