Monday, November 2, 2009

Fibonacci Numbers

C program to generate Fibonacci numbers till the user entered value.

#include
main()
{
int num;
int *a, i;;
printf("Enter the number\n");
scanf("%d", &num);

a = (int *)malloc(sizeof(int)*num);

a[0] = 0;
a[1] = 1;
printf("FIBONACCI Numbers are\n");
printf("%d\n%d\n", a[0],a[1]);

for(i = 2; i
{
a[i] = a[i-1] + a[i-2];
printf("%d\n", a[i]);
}


}

1 comment:

C.A.Gundapi said...

Some HTML format error.

the for loop shd read like below
for(i = 2; i less than num; i++)