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 :: random in range c++ 
Cpp :: c++ srand() 
Cpp :: HOW TO TURN LINK TO BUTTON IN MVC 
Cpp :: 2d vector initialization in cpp 
Cpp :: ifstream relative file path 
Cpp :: cannot find -lsqlite3 C++ compiler error 
Cpp :: Array implementation of Queue using class in c++ 
Cpp :: Area of a Circle in C++ Programming 
Cpp :: qt label set text color 
Cpp :: c++ main environment variables 
Cpp :: quotation in c++ string 
Cpp :: c++ loop pyramid 
Cpp :: Array sum in c++ stl 
Cpp :: remove at index vector c++ 
Cpp :: c++ main function 
Cpp :: c++ rule of five 
Cpp :: how to get a letter from the user c++ string 
Cpp :: push front vector cpp 
Cpp :: queue implementation using linked list in cpp 
Cpp :: convert int to binary string c++ 
Cpp :: print linked list reverse order in c++ 
Cpp :: appending int to string in cpp 
Cpp :: change to lowercase character c++ 
Cpp :: vector of strings initialization c++ 
Cpp :: c++ add object to array 
Cpp :: delete a node from binery search tree c++ 
Cpp :: how to take space separated input in c++ 
Cpp :: double to int c++ 
Cpp :: inbuilt function to convert decimal to binary in c++ 
Cpp :: continue c++ 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =