program to show Recursive Function operations of fibonacci series in C Programming

#include
#include
#include

void fibo(int *);
void fact(int *);
void rev(char *);

void main()
{
void input(void);
clrscr();
input();
// fibo(n);
getch();
}

void input(void)
{
FILE *fp;
int i,*no,ctr;
char * str,choice;

fp=fopen("input1.txt","w");
ctr=0;
while(1)
{
printf("\n DO YOU WANT TO ENTER AGAIN::");
fflush(stdin);
scanf("%c",&choice);
if(choice=='y')
{
printf("\n ENTER THE NO FOR FIBONACCII AND FACTORIAL::");
scanf("%d",no);
printf("\n ENTER THE STRING FOR REVESE::");
scanf("%s",str);
fprintf(fp,"%d %s\n",*no,str);
ctr++;
}
elsebreak;
}
fclose(fp);
fp=fopen("input1.txt","r");
for(i=1;i<=ctr;i++)
{
fscanf(fp,"%d %s",no,str);
fibo(no);
fact(no);
rev(str); // printf("\nfrom file %d %s",*no,str);
}
fclose(fp);
}
void fibo(int * n)
{
FILE * fout;
int fibonaccii(int*,int*,int*,int *,FILE *);
int fno1=0,sno1=1,*fno,*sno,*tno;
fno=&fno1;
sno=&sno1;
fout=fopen("output1.txt","a");
fprintf(fout,"\n FIBONACII SERICE OF %d",*n);
fprintf(fout,"\n%d\t%d",*fno,*sno);
fibonaccii(fno,sno,tno,n,fout);
fclose(fout);
}
int fibonaccii(int *fno,int *sno,int *tno,int * n,FILE * fout)
{
*tno=*fno+*sno;
*fno=*sno;
*sno=*tno;
if(*tno>*n)
return(0);
else
{
fprintf(fout,"\t%d",*tno);
fibonaccii(fno,sno,tno,n,fout);
}
return(0);
}

void fact(int * no1)
{
FILE * fout;
int factorial(int *,int,int *,FILE *);
int ctr1=1,*ctr,no;
ctr=&ctr1;
fout=fopen("output1.txt","a");
fprintf(fout,"\n FACTORIAL OF %d",*no1);
fprintf(fout,"\n%d",*ctr);
ctr1++;
ctr=&ctr1;
no=*no1;
factorial(no1,no,ctr,fout);
// fprintf(fout,"\n%d",*no1);
fclose(fout);
}

int factorial(int * no1,int no,int * ctr,FILE * fout)
{
if(no%*ctr==0)
{
fprintf(fout,"\t%d",*ctr);
no=no / *ctr;
factorial(no1,no,ctr,fout);
}
else
{
*ctr=*ctr+1;
if(no<=1)
{
fprintf(fout,"\t%d",*no1);
return(0);
}
factorial(no1,no,ctr,fout);
}
}
void rev(char * str)
{
FILE * fout;
int *ctr;
int reverse1(int * ,char *,FILE *);
fout=fopen("output1.txt","a");
fprintf(fout,"\n REVERSE OF %s IS::",str);
*ctr=strlen(str);
reverse1(ctr,str,fout);
fclose(fout);
}
int reverse1(int * ctr,char * str,FILE * fout)
{
char * rev=str+*ctr-1;
if(*ctr!=0)
{
fprintf(fout,"%c",*rev);
*ctr=*ctr-1;
reverse1(ctr,str,fout);
}
elsereturn(0);
}




**************************INPUT*************************************
5 jolly




**************************OUTPUT*************************************
FIBONACII SERICE OF 5
0 1 1 2 3 5
FACTORIAL OF 5
1 5
REVERSE OF jolly IS::ylloj

Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!