Advertisement
skb50bd

Array Fibonacci

Apr 18th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n,i;
  5.  
  6.     printf("Number of Terms: ");
  7.     scanf("%d",&n);
  8.  
  9.     int ara[n];
  10.  
  11.     //assign the terms
  12.     ara[0] = 0, ara[1] = 1;
  13.     for(i=2 ; i<n ; i++)
  14.         ara[i] = ara[i-1] + ara[i-2];
  15.        
  16.     //print the terms
  17.     printf("The First %d Fibonacci Terms are: ",n);
  18.     for(i=0 ; i<n ; i++)
  19.         printf("%d ",ara[i]);
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement