149k views
2 votes
Construct an algorithm to print the first 20 numbers in the Fibonacci series (in mathematics) thanks

User Starikoff
by
7.1k points

1 Answer

1 vote

Answer:

0+1=1

1+1=2

1+2=3

2+3=5

3+5=8

5+8=13

Step-by-step 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;

}

User Olaf Kock
by
7.4k points