View Code of Problem 610

#include <cstdio>
#include <iostream> 

using namespace std;

int main(){
	int k[11]={0};
	k[0]=0;
	k[1]=1;
	k[2]=2;
	k[3]=5;
	int n;
	while(cin>>n){
		if(n>0&&k[n]==0){
			k[n]=3*k[n-1]-k[n-2];
			cout<<k[n]<<endl;	
		}
		
		else
			cout<<k[n]<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 610