first create a header file in which function prototype is written
/* ex.h */
int fact(int);
source file in which function is defined
/* ex.c */
int fact(int x)
{
int i,f;
for(i=x;i>1;i--)
f=f*i;
return f;
}
now in main program we can call fact() function use ex.h header file
/* factorial.c */
#include"ex.h"
void main()
{
int n;
printf("Enter number:");
scanf("%d",&n);
printf("factorial of %d is %d",n,fact(n));
}
/*library file creation */
goto command prompt
c:\tc\bin
/* first create obj file of source file command is as */
c:\tc\bin\tcc -c ex.c /* object file ex.obj created */
c:\tc\bin\tlib ex + ex.obj /* ex.lib library file created */
c:\tc\bin\tcc ex.lib factorial.c /* library file with main program file is connected */
c:\tc\bin\tcc -c factorial.c /*program compile */
factorial /* program run simple writing program and then enter output come out */
enter number 5
factorial of 5 is 120
//* this program is checked and successfully run
No comments:
Post a Comment