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

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 :: set precision on floating numbers 
Cpp :: for llop in c++ 
Cpp :: free pair c++ 
Cpp :: c++ cash card 
Cpp :: C++ OpenCV Face Recognition 
Cpp :: left margin c++ 
Cpp :: delete an dynamic array 
Cpp :: crtdbg c++ 
Cpp :: c++ qt qtreewidget lock first column 
Cpp :: 1/2(-3-3)(-3+4) 
Cpp :: Extended Euclid Algorithm Recursive Solution 
Cpp :: how to replace a element in a vector c++ using index 
Cpp :: sinh to hop c++ 
Cpp :: iff cpp 
Cpp :: draw point sfml 
Cpp :: Character convert c++ 
Cpp :: find a member variable in a vector of objects cpp 
Cpp :: C++ Dynamic allocation failing 
Cpp :: c++ hsl to rgb integer 
Cpp :: ue4 c++ oncomponentbeginoverlap 
Cpp :: Arduino Access Point ESP8266 
Cpp :: convert c++ code to exe 
Cpp :: qt widget list set selected 
Cpp :: 496. Next Greater Element I.cpp 
Cpp :: cpp super 
Cpp :: Stack Modified 
Cpp :: 18 in 12 hour time 
Cpp :: longest increasing subsequence nlogn c++ 
Cpp :: c++ press any key 
Cpp :: english to french typing online 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =