Y. Easy Fibonacci – Codeforces Problem Solution in C++

Disclaimer: Make sure you tried enough before checking the solution

Problem: https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/Y

#include<iostream> 
using namespace std; 
int main() { 
	int size;
	cin>>size;
	int start = 0,second = 1;
	if(size == 1){
		cout<<start<<endl;
	} else if(size == 2){
		cout<<start<<" "<<second<<endl;
	} else {
		cout<<start<<" "<<second<<" ";
		for(int i=2;i<size;i++){
			int res = start + second;
			cout<<res<<" ";
			start = second;
			second = res;
		}
	}
}

Assiut University Training – Newcomers solution

Leave a Comment