Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Join our platform to connect with experts ready to provide detailed answers to your questions in various areas. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.

Construct an algorithm to print the first 20 numbers in the Fibonacci series (in mathematics) thanks

Sagot :

Answer:

0+1=1

1+1=2

1+2=3

2+3=5

3+5=8

5+8=13

Explanation:

// C++ program to print

// first n Fibonacci numbers

#include <bits/stdc++.h>

using namespace std;

 

// Function to print

// first n Fibonacci Numbers

void printFibonacciNumbers(int n)

{

   int f1 = 0, f2 = 1, i;

 

   if (n < 1)

       return;

   cout << f1 << " ";

   for (i = 1; i < n; i++) {

       cout << f2 << " ";

       int next = f1 + f2;

       f1 = f2;

       f2 = next;

   }

}

 

// Driver Code

int main()

{

   printFibonacciNumbers(7);

   return 0;

}