View Code of Problem 23

#include<stdio.h>
int main()
{
	int n;
	long int a[100] = {0};
	while (scanf("%d",&n)!=EOF)
	{
		if (n == 0) break;
		a[1] = 1;
		a[2] = 2;
		for (int i = 3; i <= n; i++)
		{
			a[i] = a[i - 1] + a[i - 2];
		}
		printf("%ld\n", a[n]);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 23