C Program Fibonacci with Static Variable

This program is for Fibonacci Series using a Static variable. This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1


#include<stdio.h>
#include<conio.h>
void fib();
void main()
{
int n,i;
clrscr();
printf("Enter the times you want the series\t");
scanf("%d",&n);
for(i=0;i<n;i++)
{
fib();
}
getch();
}

void fib()
{
static int a=0,b=1,c;
if(a==0)
printf("%d\t%d",a,b);
c=a+b;
a=b;
b=c;
printf("\t%d",c);
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a comment