Advertisement
sedran

fibo

May 6th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.31 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int fibo(int n) {
  4.     int f0, f1,temp,i;
  5.     f0 = 0;
  6.     f1 = 1;
  7.     for(i=3; i<=n; i++) {
  8.         temp = f0;
  9.         f0 = f1;
  10.         f1 = temp + f1;
  11.     }
  12.     return f1;
  13. }
  14.  
  15. int main(){
  16.     int n;
  17.     while( n != 0 ) {
  18.         scanf("%d",&n);
  19.         printf("%d. fibonacci number is %d\n", n, fibo(n));
  20.     }
  21.     anykey();
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement