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 n;
  while(scanf("%d",&n)!=EOF&&n){
    printf("%d\n",sum(n));
  }
}

Double click to view unformatted code.


Back to problem 23