Pages

Ads 468x60px

Saturday, 2 June 2012

C Program For FIBINACCI SERIES USING ARRAY




C Program For FIBINACCI SERIES USING ARRAY



We have now used a variety the features of C. This final example will introduce
 the array. The program prints out a table of Fibonacci numbers. These are
 defined by a series in which any element is the sum of the previous two elements. 
This program stores the series in an array, and after calculating it, prints the numbers out as a table.



CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a[20];
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
a[0]=0;
a[1]=1;
printf("%d\n",a[0]);
printf("%d\n",a[1]);
for(i=2;i<n;i++)
{
a[i]=a[i-1]+a[i-2];
printf("%d\n",a[i]);
}
getch();
}

0 comments:

Post a Comment

Total Pageviews