The surface area of a sphere is 4 pi r2 the surface are of c
Solution
STEPS FOR ADDING OUR OWN FUNCTIONS IN C LIBRARY:
STEP 1:
Create file “surfaceArea.c” and add the below code in it.
#define PI (3.141592653589793)
using namespace std;
float surfaceAreaOfSphere(int R){
return 4*PI*R*R;
}
float surfaceAreaOfCone(int R, int H){
return 2*PI*R*(H+R);
}
float surfaceAreaOfCube(int L){
return 6*L*L;
}
STEP 2:
Compile “surfaceArea.c”
STEP 3:
“surfaceArea.obj” file would be created which is the compiled form of “surfaceArea.c” file.
STEP 4:
Use the below command to add this function to library (in turbo C).
c:\\> tlib math.lib + c:\\surfaceArea.obj
+ means adding c:\\surfaceArea.obj file in the math library.
We can delete this file using – (minus).
STEP 5:
Create a file “surfaceArea.h” & declare prototype of the three functions like below.
float surfaceAreaOfSphere(int R);
float surfaceAreaOfCone(int R, int H);
float surfaceAreaOfCube(int L);
Now, surfaceArea.h file contains prototype of the three function.
Note: Please create, compile and add files in the respective directory as directory name may change for each IDE.
STEP 6:
Use our newly added library function in a C program.
# include <stdio.h>
// Including our user defined function.
# include “c:\\\\ surfaceArea.h” // Path where you have saved surfaceArea.h file
int main()
{
cout << \"Hello Humans\"
<< endl << surfaceAreaOfSphere(10) << endl
<< surfaceAreaOfCone(10) << endl
<< surfaceAreaOfCube(10) << endl;
return 0;
}
---------------------------------------------------------------------THE END---------------------------------------------------------------------------

