Answer:
Input : n = 3
Output : 1 1 2
Input : n = 7
Output : 1 1 2 3 5 8 13
Recommended: Please solve it on “PRACTICE ” first, before moving on to the solution.
C++
// 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;
for (i = 1; i <= n; i++)
cout<<f2<<" ";
int next = f1 + f2;
f1 = f2;
f2 = next;
}
// Driver Code
int main()
printFibonacciNumbers(7);
return 0;
follow me ❤️❤️❤️
...
.
..
Copyright © 2024 EHUB.TIPS team's - All rights reserved.
Answers & Comments
Answer:
Hey mate here is your answer...
Input : n = 3
Output : 1 1 2
Input : n = 7
Output : 1 1 2 3 5 8 13
Recommended: Please solve it on “PRACTICE ” first, before moving on to the solution.
C++
// 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;
for (i = 1; i <= n; i++)
{
cout<<f2<<" ";
int next = f1 + f2;
f1 = f2;
f2 = next;
}
}
// Driver Code
int main()
{
printFibonacciNumbers(7);
return 0;
hope it's helpful for you
follow me ❤️❤️❤️
}
Answer:
...
.
.
.
.
.
.
.
.
.
.
...
.
..
..
.