Skip to main content

Math library

This post lists the important functions available in the “math.h” library of C with their examples. Before continuing, you must know that we need to include the “math.h” library while compiling our program by using -lm ($cc -c filename.c  $cc -o filename filename.c -lm).
Function     Description                                 Example
sqrt(x)       square root of x                              sqrt(4.0) is 2.0
                                                                         sqrt(10.0) is 3.162278
exp(x)        exponential (ex)                            exp(1.0) is 2.718282
                                                                         exp(4.0) is 54.598150
log(x)        natural logarithm of x (base e)       log(2.0) is 0.693147
                                                                         log(4.0) is 1.386294
log10(x)     logarithm of x (base 10)                log10(10.0) is 1.0
                                                                         log10(100.0) is 2.0
fabs(x)        absolute value of x                       fabs(2.0) is 2.0
                                                                         fabs(-2.0) is 2.0
ceil(x)        rounds x to smallest integer not less than x 
                                                                        ceil(9.2) is 10.0
                                                                        ceil(-9.2) is -9.0
floor(x)       rounds x to largest integer not greater than x 
                                                                        floor(9.2) is 9.0
                                                                        floor(-9.2) is -10.0
pow(x,y)    x raised to power y (xy)                pow(2,2) is 4.0
fmod(x)     remainder of x/y as floating-point number 
                                                                        fmod(13.657, 2.333) is 1.992
sin(x)       sine of x (x in radian)                      sin(0.0) is 0.0
cos(x)      cosine of x (x in radian)                  cos(0.0) is 1.0
tan(x)       tangent of x (x in radian)                tan(0.0) is 0.0

Comments

Popular posts from this blog

KTU Mandatory C programs for Laboratory and Solutions

LIST OF LAB EXPERIMENTS 1. Familiarization of Hardware Components of a Computer 2. Familiarization of Linux environment – Programming in C with Linux 3. Familiarization of console I/O and operators in C     i) Display “Hello World”     ii) Read two numbers, add them and display their sum     iii) Read the radius of a circle, calculate its area and display it 4. Evaluate the arithmetic expression ((a -b / c * d + e) * (f +g))   and display its solution. Read the values of the variables from the user through console 5. Read 3 integer values, find the largest among them. 6. Read a Natural Number and check whether the number is prime or not 7. Read a Natural Number and check whether the number is Armstrong or not 8. Read n integers, store them in an array and find their sum and average 9. Read n integers, store them in an array and search for an element in the    array using an algorithm for Linear Search 10.Read n ...

PROGRAMMING IN C KTU EST 102 THEORY AND LAB NOTES

PROGRAMMING IN C  KTU  EST 102  THEORY AND LAB   COMMON FOR ALL BRANCHES About Me Syllabus Theory Syllabus Lab Model Question Paper EST 102 Programmin in C University Question Papers  and evaluation scheme   EST 102 Programming in C  Introduction( Lab) Introduction to C programming Linux History and GNU How to create a bootable ubuntu USB stick Installing  Linux Install Linux within  Windows Virtual Box and WSL Linux Basic Features and Architecture Basic Linux Commands Beginning C Programming Compiling C programs using gcc in Linux Debugging C program using gdb Module 1: Basics of computer hardware and software          Module-1 Reading Material Basics of Computer Architecture Hardware and Software System Software and Application Software  Programming Languages ( High level, Low level and Machine Language) and Translators ( Compiler, Interpreter, Assembler) Algorithm, Flowcharts and Pseudo code Program Devel...

Programming Languages ( High level, Low level and Machine Language) and Translators ( Compiler, Interpreter, Assembler)

Programming Languages A Programming Language consists of a set of vocabulary and grammatical rules, to express the computations and tasks that the computer has to perform. Programming languages are used to write a program, which controls the behavior of computer, codify the algorithms precisely, or enables the human-computer interface. Each language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions.  The programming language should be understood, both by the programmer (who is writing the program) and the computer. A computer understands the language of 0∙s and 1∙s, while the programmer is more comfortable with English-like language. Programming Language usually refers to high-level languages like COBOL, BASIC, FORTRAN,BCPL, C, C++, Java,Python etc. High level programming language is chosen depending on the type of the application you are going to develop.For example if we are developing android mobile applications we ...