Print Fibonacci series
Input: ‘n’ = 5
Output: 0 1 1 2 3
Explanation: First 5 Fibonacci numbers are: 0, 1, 1, 2, and 3.
#include <iostream>
using namespace std;
int main() {
int n = 5;
int f = 0 , s = 1;
for(int i = 0; i<n;i++){
cout<<f<<" ";
int tn = f+s;
f = s;
s = tn;
}
return 0;
}
output: 0 1 1 2 3
take value from user:
No comments: