View Code of Problem 23

#include <iostream>
using namespace std;

//int sum(int day){
//    if(day == 1||day == 2||day == 3)
//        return day;
//    else
//        return sum(day-1)+sum(day-2);
//}

int main(){
    int i,j,m;
    long int a[1000];
    while(scanf("%d",&m)!=EOF){
        if(m==0)
            break;
        a[0]=0;
        a[1]=1;
        for(i=2;i<=m+1;i++)
        {
            a[i]=a[i-1]+a[i-2];
            
        }
        printf("%ld\n",a[m+1]);
    }
}

Double click to view unformatted code.


Back to problem 23