Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Fibonacci in c++

#include<iostream>
using namespace std;

int main()
{
	int n, t1 = 0, t2 = 1, sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		if (i == 1)
			cout << t1 << " ";
		else if (i == 2)
			cout << t2 << " ";
		else
		{
			sum = t1 + t2;
			cout << sum << " ";
			t1 = t2;
			t2 = sum;
		}
	}
	return 0;
}
Comment

Fibonacci numbers in c++,c

//1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
int a=1,b=1;
cout<<a<<" "<<b<<" ";
	for(int i=0;i<10;i++){
		c=a+b;
		a=b;
		b=c;
		cout<<c<<" ";
	}
// 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
// a, b, c,......
//  , a, b, c,.....
//  ,  , a, b, c,....	
Comment

c++ fibonacci

#include <iostream>
using namespace std;

int main() {
	
	int n;
	cin >> n;
	
	int a = 0;
	int b = 1;
	int c = 1;
	for(int i = 1; i<=n;i++){
		c = a+b;
		a = b;
		b = c;
	}
	
	cout << c; // Here you can output the variable b or c, at the end of the for loop they are the same
	// This outputs the N-th fibbonnaci number
	
	return 0;
}
Comment

fibonacci sequence c++

#include <bits/stdc++.h> 
using namespace std ;
int main (){
             int n,p1=0,p2=1,d;
             cin>>n;

             for( ;0<n;n--){
                cout<<p1<<" ";
                 d=p1;
                p1+=p2;    
                p2=d;
             
             }
             return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: heap buffer overflow c++ 
Cpp :: how to convert character to lowercase c++ 
Cpp :: cpp split string by space 
Cpp :: how to make a n*n 2d dynamic array in c++ 
Cpp :: getch c++ library 
Cpp :: c++ mst kruskal 
Cpp :: push front vector cpp 
Cpp :: c++ ros publisher 
Cpp :: find in set of pairs using first value cpp 
Cpp :: opencv rgb to gray c++ 
Cpp :: convert int to binary string c++ 
Cpp :: how to split a string into words c++ 
Cpp :: random number in a range c++ 
Cpp :: C++ switch cases 
Cpp :: random number cpp 
Cpp :: run c++ program in mac terminal 
Cpp :: struct and array in c++ 
Cpp :: c++ vector loop delete 
Cpp :: fstring from float c++ ue4 
Cpp :: remove last index of the string in c++ 
Cpp :: C++ std::string find and replace 
Cpp :: how to convert string into lowercase in cpp 
Cpp :: find max element in array c++ 
Cpp :: hamming distance c++ 
Cpp :: how to get size of 2d vector in c++ 
Cpp :: string to uint64_t c++ 
Cpp :: c++ output 
Cpp :: how to input a vector when size is unknown 
Cpp :: change colour of output to terminal c++ 
Cpp :: selection sort c++ algorithm 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =