![]() |
The Standard Function Library in C is a huge library of sub-libraries, each of which contains the code for several functions. In order to make use of these libraries, link each library in the broader library through the use of header files. The definitions of these functions are present in their respective header files. In order to use these functions, we have to include the header file in the program. Below are some header files with descriptions:
Implementation: Let’s discuss the implementation of the basic libraries with a C program: 1. stdio.h: This library is use to use the printf() function, the header file <stdio.h> should be included in the program. Below is the C program to implement the above approach: C
Output
GEEKS FOR GEEKS Note: If printf() function is used without including the header file <stdio.h>, an error will be displayed. 2. math.h– To perform any operation related to mathematics, it is necessary to include math.h header file. Example 1: sqrt() Syntax- double sqrt(double x) Below is the C program to calculate the square root of any number: C
Output
Square root of 12.50 = 3.54 Example 2- pow(): Syntax: double pow(double x, double y) Below is the C program to calculate the power of any number: C
Output
10.0^2.0 = 100.00 Example 3- sin(): Syntax: double sin(double x) Below is the C program to calculate the sine of an argument: C
Output
sin(2.30) = 0.75 sin(-2.30) = -0.75 sin(0.00) = 0.00 Example 4- cos(): Syntax: double cos(double x); Below is the C program to calculate the cosine of an argument: C
Output
cos of 0.52 radian = 0.87 Example 5- tan(): Syntax: double tan(double x); Below is the C program to calculate the tangent of the argument: C
Output
tan(2.30) = -1.12 tan(-2.30) = 1.12 Example 6- log(): Syntax- double log( double arg ); Below is the C program to calculate the natural logarithm of an argument- C
Output
log(5.6) = 1.72 3. float.h: The float.h header file of the C Standard Library contains a set of various platform-dependent constants related to floating-point values. Below is the C program to implement the above approach- C
Output
Maximum value of float = 3.4028234664e+38 Minimum value of float = 1.1754943508e-38 4. limits.h: The limits.h header determines various properties of the various variable types. The macros defined in this header limits the values of various variable types like char, int, and long. Below is the C program to implement the above approach- C
Output
Number of bits in a byte 8 Minimum value of SIGNED CHAR = -128 Maximum value of SIGNED CHAR = 127 Maximum value of UNSIGNED CHAR = 255 Minimum value of SHORT INT = -32768 Maximum value of SHORT INT = 32767 Minimum value of INT = -2147483648 Maximum value of INT = 2147483647 Minimum value of CHAR = -128 Maximum value of CHAR = 127 Minimum value of LONG = -9223372036854775808 Maximum value of LONG = 9223372036854775807 5. time.h: This header file defines the date and time functions. Below is the C program to implement time() and localtime() functions- C
Output
Sun May 30 17:27:47 2021 Today is Sunday, May 30. The time is 05:27 PM. 6. string.h: For using string functions, it is necessary to include string.h header file in the program. Example 1: strcat(): In C programming, the strcat() functions are used to concatenate(join) two strings. This function concatenates the destination string and the source string, and the result is stored in the destination string. Syntax- char *strcat(char *destination, const char *source) Below is the C program to implement strcat(): C
Output
Geeks For Geeks Example 2- strcmp(): It compares two strings. If the return value is 0 then the strings are equal or if the return value is non-zero then the strings are not equal. Syntax: int strcmp (const char* str1, const char* str2); Below is the C program to implement strcmp(): C
Output
strcmp(str1, str2) = -32 strcmp(str1, str3) = 0 Example 3 – strcpy(): The strcpy() function copies the string pointed by the source to the destination. Syntax: char* strcpy(char* destination, const char* source); Below is the C program to implement the strcpy(): C
Output
Geeks For Geeks Example 4 – strlen(): This function calculates the length of the given string. Syntax: int strlen(char a[]); Below is the C program to implement strlen(): C
Output
Length of string a = 7 Length of string b = 15 7. complex.h: Functions in this header file are used to perform various operations on complex numbers. Complex numbers are the ones with the real and imaginary parts. Below is the C program to implement conjugate of a complex number- C
Output: z = 1.3 - 4.9i 8. assert.h: Assertions are statements used to test assumptions made by programmers. For example, we may use an assertion to check if the pointer returned by malloc() is NULL or not. Syntax- void assert(int expression); C++
Output Assertion failed: x==7, file test.cpp, line 13 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. |
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |