Built-in Functions

Unit 8. Built-in Functions
        8.1. Mathematical Functions
        8.2. String Functions
        8.3. Character Functions.

Built-in Functions



Function
Function is a program which is written to perform a task.

Functions can be categorized in to two types
1. Built in Functions
     -Mathematical Functions Click here for Math Function (Inbuilt)
     -String Functions Click here for example
     -Character Functions Click here for example
2. User Defined Functions

Built in functions are those which are already available in C Library.They can be used in any program for example printf(), scanf(),ceil(),strcpy() etc

User defined function is function written by the user.

main() is also a user defined function.





Built-in Functions
1.Mathematical Functions

Library  #include<math.h>

1.abs()
abs() function returns the absolute value of the integer parameter.The absolute value of integer is always positive.

Syntax:
        int abs(int a);
Example:
          int a=-30;
       printf("Absolute value of a = %d\n", abs(a));
       Absolute value of a =30

for floating values it is fabs()

2. ceil()
ceil() function return nearest value which is greater than or equal to the argument passed.
Syntax:
double ceil(double a)

Example:
       float i=5.2;       printf("ceil of  %f is  %f\n", i, ceil(i));

       ceil of 5.200000 is 6.000000


3. floor()
floor() function return nearest value which is less than or equal to the argument passed.
Syntax:
        double floor(double a)
Example:
       float i=5.2;       printf("floor of  %f is  %f\n", i, floor(i));

       ceil of 5.200000 is 4.000000

4. pow()
pow() function return the power of the number.
Syntax:
        double pow(double base,double exp)
Example:
       printf("4 power 2= %f\n",pow(4,2));

       4 power 2= 16.000000

5. log10()
log10() function return value of base 10 algorithm.

Syntax:
         double log10(double a)

Example:
       float a=10.0;       printf("The value of log(%f) : %f \n", a,log10(a));

       The value of log(10.000000) : 1.000000

6. sqrt()
sqrt() function will return the square root of the given number
Syntax:
        double sqrt(double a)

Example:
       printf ("sqrt of 9 = %f\n", sqrt (9) );

          sqrt of 9 = 3.000000

7. exp()
exp() function will calculate the exponential value of the power.
Syntax:
         double exp(double a)

Example:
       float a=1.0;       printf("The value of exp(%f) : %f \n", a,exp(a));

       The value of exp(1.000000) : 1E

8. sin()

9.cos()

10.tan()

Sin() cos() and tan() are used to calculate the sine, cosine and tangent values.
Example: 
              float j=45.0;

             printf("The value of sin(%f) : %f \n", j, sin(j)); 
             printf("The value of cos(%f) : %f \n", j, cos(j));
             printf("The value of tan(%f) : %f \n", j, tan(j));


       The value of sin(45) : 0.850903

       The value of cos(45) : 0.525321

       The value of tan(45) : 1.619775

0 comments:

Post a Comment