#include <stdio.h> #include <stdlib.h> #include <string.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main() { int m,i; while(scanf("%d",&m)!=EOF){ if(m==0){ break; } int a[1000]={0,1,2}; for(i=3;i<=m;i++){ a[i]=a[i-1]+a[i-2]; } printf("%d\n",a[m]); } } |
Double click to view unformatted code.