Pages

Tuesday, November 30, 2010

UVA Problem#900

Question:

Solution:
1. if the length is 1 output will be 1, if the length is 2 out put will be 2, if the length is 3 output will be 3, if the length is 4 output will be 5. Doesn't the output series look familiar to you? 1 2 3 5 ...... Ya right! Its a Fibonacci series!
2. You can have the first 50 Fibonacci numbers in an array and then just print the answer according to the input.

int main(){
 int fib[ ] = {1,2,3,5,8,13,21,.   .. .  . .. . .. ,7778742049, 12586269025};
int n;
while(1){
scanf("%d", &n);
if(n==0)
break;
printf("%d\n", fib[n-1] );
}
return 0;
}

No comments:

Post a Comment