View Code of Problem 23

#include<bits/stdc++.h>
using namespace std;

int main() {

	int m;
	while(cin>>m&&m!=0){
		if(m==1){
			cout<<1<<endl;
		}else if(m==2){
			cout<<2<<endl;
		}else{
			int pre=1,now=2;
			for(int i=3;i<=m;i++){
				int k=now;
				now+=pre;
				pre=k;
			}
			cout<<now<<endl;
		}
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 23