View Code of Problem 23

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int M;
    while(cin>>M&&M!=0){
    long int a[999];
    a[1]=1,a[2]=2;
    if(M>2){
    for(int i=3;i<=M;i++){
        a[i]=a[i-1]+a[i-2];
        }
    }
    cout<<a[M]<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 23