Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #fibonacci
ADD COMMENT
Topic
Name
1+7 =