C Header Files

header file is important part of c programming. because they contain group of functions. if we include a header file then we are capable to utilize to those function in our program. C language are provides various predefined header files. we are utilize those header file functions. But first need to include those particular header file using #include preprocessor directives.

Including header file syntax

//predefined header files
#include <file_name>

//user defined header file
#include <path_and_file_name>

Extension of header file is (.h) .header file are two type

Header File Type

Perdefined Header File

Here given standard header file in c programming.

<math.h> <stdio.h> <time.h> <string.h>
<assert.h> <ctype.h> <errno.h> <limits.h>
<float.h> <locale.h> <stddef.h> <setjmp.h>
<stdarg.h> <signal.h> <stdlib.h>

<math.h>

This header file support various math functions. This header file include various math functions. look at view following functions.

sqrt()

this function are calculate square root. square function are accept one parameter. parameter value are in form of double. we can also pass integer value.and there function are return one double value.

Syntax

double sqrt(double var);

For example

/*
 Example math.h sqrt function.
*/
#include <stdio.h>
#include <math.h>

int main(){
  //print square root of 16
  printf("square root of [%d] is : %lf\n",16,sqrt(16));
  
  printf("square root of [%lf] is : %lf\n",49.4,sqrt(49.4));
}

Output

square root of [16] is : 4.000000
square root of [49.400000] is : 7.028513

pow()

This function are calculate power of two number. first is base let say assume that this is (a). and second one is b. then this function are calculate (a^b).

Syntax

 /*return double value
  accept double value*/
  double pow(double a, double b);

For example

/*
 Example math.h pow function.
*/
#include <stdio.h>
#include <math.h>

int main(){
  
  printf("%d ^ %d : %lf\n",3,3,pow(3,3));
  
  printf("%lf ^ %d: %lf\n",4.3,3,pow(4.3,3));
}

Output

3 ^ 3 : 27.000000
4.300000 ^ 3: 79.507000

ceil()

return ceil value. this value are greater than or equal to x.

Syntax

double ceil(double x);
/*
 Example math.h ceil function.
*/
#include <stdio.h>
#include <math.h>

int main(){
  printf("%lf\n",ceil(8.34));
  printf("%lf\n",ceil(120.5));
}

Output

9.000000
121.000000

floor()

/*
 Example math.h floor function.
*/
#include <stdio.h>
#include <math.h>

int main(){
  printf("%lf\n",floor(8.34));
  printf("%lf\n",floor(120.5));
}

Output

8.000000
120.000000

fabs()

/*
 Example math.h fabs function.
*/
#include <stdio.h>
#include <math.h>

int main(){
  printf("%lf\n",fabs(8.34));
  printf("%lf\n",fabs(-120.5)); //nagative value
}

Output

8.340000
120.500000

cos()

/*
 Example math.h cos function.
*/
#include <stdio.h>
#include <math.h>
int main(){
  printf("cos(4)  : %lf\n",cos(4));
  printf("cos(45) : %lf\n",cos(45));
}

Output

cos(4)  : -0.653644
cos(45) : 0.525322

sin()

/*
 Example math.h sin function.
*/
#include <stdio.h>
#include <math.h>
int main(){
  printf("sin(90)  : %lf\n",sin(90));
  printf("sin(145) : %lf\n",sin(145));
}

Output

sin(90)  : 0.893997
sin(145) : 0.467745

log10()

/*
 Example math.h log10 function.
*/
#include <stdio.h>
#include <math.h>
int main(){
  printf("log10(90)  : %lf\n",log10(90));
  printf("log10(147) : %lf\n",log10(147));
}

Output

log10(90)  : 1.954243
log10(147) : 2.167317

© 2019, regularcodes.com, All rights reserved