#include<stdio.h>
#include<conio.h>
#include<ctype.h>
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