Here is a simple example:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i = -42;
    int j = abs(i);
    printf("i = %d, j = %d\n", i, j);
    return 0;
}

LIVE DEMO

Answer from Paul R on Stack Overflow
🌐
W3Schools
w3schools.com › c › c_ref_math.php
C math (math.h) Library Reference
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... The <math.h> library has many functions that allow you to perform mathematical tasks on numbers.
Discussions

C Programming Math Functions #include <stdlib.h> abs() - Stack Overflow
If the author adds details in comments, ... them into the question. Once there's sufficient detail to answer, vote to reopen the question. Closed 10 years ago. ... I start learing C programming from "Beginning Programming with C For Dummies" by Dan Gookin. I have a problem with understanding "C Math Functions" - my question ... More on stackoverflow.com
🌐 stackoverflow.com
Parameter Space of Quasi-characters of Idèle Class Group
🌐 r/math
How to define a function in C
You can't. Your insistence that C has to follow mathematical rules, notwithstanding that you have already once been told that C does not distinguish between what you call a procedure and a function, just makes you a tool with too much self esteem. More on reddit.com
🌐 r/C_Programming
41
0
February 1, 2020
Is there in AVG function in C? And also, is a importing a module and including a library the same?
There are important differences between #include and python's import math. When you use #include in C, it tells the preprocessor to put the contents of the targeted file in your current file at the location of the include statement. This is usually done with a header file (.h), which can contain anything a .c file contains, but usually contains things like function declarations (but not definitions) and structs. This is enough to allow you to use the names in your own code, and compile it to an object file, but a final executable will still need definitions for its functions, so you'll have to link them in one way or another. This could involve linking to static (.a) or dynamic (.so) libraries (gcc -lm file.c, to link to the math library), or it could involve specifying multiple .c files together in your compilation (gcc -o myapp foo.c bar.c). Python's import, on the other hand, executes the module it imports, which handles both declaring and defining the functions listed in it, so no further work needs to be done before you can use the functions and classes you've imported. Another difference is that import math adds the name math to the current namespace, while #include adds all the names in that header file to the current namespace. Semantically, #include is closer to from math import * than import math. More on reddit.com
🌐 r/C_Programming
6
0
September 25, 2014
People also ask

How do I include and use math functions in a C program?
To use math functions in a C program, include the math library by adding `#include ` at the beginning of your code. Compile your program with the `-lm` flag (e.g., `gcc program.c -lm`). This enables you to call various math functions like `sqrt()`, `pow()`, and `cos()`.
🌐
vaia.com
vaia.com › c math functions
C Math Functions: Definition & Examples | Vaia
What are the limitations of using math functions in C?
Math functions in C may face precision limitations due to floating-point representation errors, potential domain errors if used improperly (e.g., passing negative values to sqrt), and limited portability across different platforms if compiler-specific libraries are used. Additionally, certain operations might result in undefined behavior if not correctly handled.
🌐
vaia.com
vaia.com › c math functions
C Math Functions: Definition & Examples | Vaia
How do I handle errors when using C math functions?
When using C math functions, handle errors by checking the `errno` variable, which is set on errors like domain and range errors, or use the function `feclearexcept` and `fetestexcept` to check floating-point exceptions. Additionally, `math_errhandling` can be used to determine how mathematical errors are reported.
🌐
vaia.com
vaia.com › c math functions
C Math Functions: Definition & Examples | Vaia
🌐
CodeRunner
coderunner.org.nz › mod › forum › discuss.php
CodeRunner: C program with math.h
August 12, 2019 - Specifying linkargs is essential for math.h, and compileargs is required for M_PI (refer link for details). ... Many, many thanks for your last answer it Works perfectly. Now, is there any kind of question in coderunner to process pseudocode ?
🌐
Vaia
vaia.com › c math functions
C Math Functions: Definition & Examples | Vaia
These functions include basic operations such as `sqrt` for square root, `pow` for exponentiation, and `sin`, `cos`, `tan` for trigonometric calculations. Understanding these functions is crucial for efficient coding in C, as they enable programmers to handle complex mathematical computations ...
🌐
Programiz
programiz.com › c-programming › library-function › math.h
C math.h
The C++ mah.h header file declares a set of functions to perform mathematical operations such as: sqrt() to calculate the square root, log() to find natural logarithm of a number etc.
🌐
Studocu
studocu.com › jomo kenyatta university of agriculture and technology › diploma in it › using c math functions
Essential C Math Functions Overview and Examples
Types of C Math Functions: ... Example #include <stdio> #include <math> int main() { double number = 3; double result = round(number); printf("The rounded value of % is %\n", number, result); return 0; } 2.
Find elsewhere
🌐
Wikipedia
en.wikipedia.org › wiki › C_mathematical_functions
C mathematical functions - Wikipedia
February 14, 2026 - LLVM's libm, which is correctly rounded (i.e. errors from the mathematically correct result are lower than 0.5 unit in the last place) Arénaire project's CRlibm (correctly rounded libm), and its successor MetaLibm, which uses Remez algorithm to automatically generate approximations that are formally proven. Rutger's RLIBM, which provides correctly rounded functions in single precision.
🌐
Scribd
scribd.com › document › 720040533 › Session-7-part-1-Mathematical-function-from-math-header-file-in-c
Session-7 part-1 - Mathematical function from math header file in c
printf("Absolute value of n = %d \n",n); return 0; } EXAMPLE PROGRAM FOR FLOOR( ) FUNCTION IN C: #include <stdio.h> #include <math.h> int main() { float i=5.1, j=5.9, k=-5.4, l=-6.9; printf("floor of %f is %f\n", i, floor(i)); printf("floor of %f is %f\n", j, floor(j)); printf("floor of %f is %f\n", k, floor(k)); printf("floor of %f is %f\n", l, floor(l)); return 0; }
🌐
w3resource
w3resource.com › c-programming-exercises › math › index.php
C programming exercises: Math - w3resource
October 24, 2025 - Example 1: Input: n = 121 Output: Next smallest palindrome of 121 is 131 ... Write a C program to calculate e raised to the power of x using the sum of the first n terms of the Taylor Series.
Top answer
1 of 3
2

Here is a simple example:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int i = -42;
    int j = abs(i);
    printf("i = %d, j = %d\n", i, j);
    return 0;
}

LIVE DEMO

2 of 3
1

Besides the examples given above,functions work just like a mathematical function in that y = f(x) you put in x and it returns a y(of course some dont return anything and some dont take in anything)

now what you need to do is to catch that value when it returns it by storing it into some memory location which is called a variable that you declare

its also important that you know what the return type is so that you dont truncate or lose some part of the result

for example if the result is a floating point number then you need to return the value into a float/double variable and if it is a integer you can store it in either int or double/float

also if it is a char you would probably want it to be returned to a char variable and so on and so forth

So any function that you write or that you use from somebody elses library/header is going to work like that

It takes in an argument(sometimes it can even take no arguments and you just use it by calling it with parentheses, parentheses must always be typed because otherwise it will look like a variable or something else and convention says so) and it returns some result(if it does return a result) or does something else unrelated to the calling functions variables/values

So hopefully that explains what functions are, and how you can use them

Now all of this described also applies to the functions you posted about, they have a set algorithm that they do which somebody else wrote, and you just give it the argument, and catch the return type and it will do what it says it intended to do i.e abs() gives you the absolute value, pow() returns the square of some base and so on

🌐
Tuts Make
tutsmake.com › home › math functions in c programming
Math Functions in C Programming - Tuts Make
November 4, 2022 - Using the math sqrt() function, you can find square root of a number with sqrt in c program ; as follows:
🌐
Ubaldo Acosta Soto
ictdemy.com › c-language › basics › mathematical-functions-in-the-c-language-the-math-library
Lesson 11 - Mathematical functions in the C language - The Math library
We'll certainly use round() very often. I've used the other functions to do things like determine the number of pages in a guestbook. For example, when we have 33 comments and we only print 10 comments per page. Therefore, they'd occupy 3.3 pages.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-library-math-h-functions
C Library math.h Functions - GeeksforGeeks
April 3, 2023 - // C code to illustrate // the use of ceil function. #include <math.h> #include <stdio.h> int main() { float val1, val2, val3, val4; val1 = 1.6; val2 = 1.2; val3 = -2.8; val4 = -2.3; printf("value1 = %.1lf\n", ceil(val1)); printf("value2 = %.1lf\n", ...
🌐
Ruraluniv
portal.ruraluniv.ac.in › LMSUpload › 66 › 123 › 123002.pdf pdf
C Mathematical Functions C Programming allows us to ...
The commonly used functions of math.h ... Let's see a simple example of math functions found in math.h header file. ... angle. It is used to evaluate the trigonometric sine function of an angle. It takes the radian angle · as input and returns the sin of that angle. It is defined inside <math.h> header file. ... Returns the sine of the given radian angle which ranges between +1 to -1. ... The below program demonstrates how we can calculate the cosine of various angles in C.
🌐
Tutorjoes
tutorjoes.in › c_programming_tutorial › math_in_c
Performing Mathematical Operations in C : A Comprehensive Guide
//Math Function #include<stdio.h> #include<math.h> int main() { printf("\nSQRT : %0.2f",sqrt(4)); printf("\nPOW : %0.2f",pow(2,3)); printf("\nabs : %d",abs(-25)); printf("\nCEIL : %f",ceil(3.8)); printf("\nCEIL : %f",ceil(3.2)); printf("\nFLOOR : %f",floor(3.8)); printf("\nFLOOR : %f",floor(3.2)); printf("\nROUND : %f",round(3.8)); printf("\nROUND : %f",round(3.2)); return 0; } To download raw file Click Here
🌐
Wikibooks
en.wikibooks.org › wiki › C_Programming › math.h
C Programming/math.h - Wikibooks, open books for an open world
February 20, 2006 - Mathematical library functions that operate on integers, such as abs, labs, div, and ldiv, are instead specified in the stdlib.h header. ... (For functions to convert strings to floating point numbers (atof(), strtod(), etc.), see C Programming/C Reference/stdlib.h.)
🌐
YouTube
youtube.com › watch
Learn C math functions in 5 minutes! 🧮 - YouTube
#coding #programming #cprogramming Here is a few math related functions in C that you should be aware of as a beginner float x = 3; x = sqrt(x); x =...
Published   March 1, 2025
🌐
Tpoint Tech
tpointtech.com › c-math
C Math Functions - Tpoint Tech
Trigonometry, exponentiation, logarithms, rounding, and other mathematical operations are available in the Cs math library. These approaches are more suited ...
🌐
Gdcbeerwah
gdcbeerwah.edu.in › Files › 4506570f-d508-4426-9ccc-012bcbb608c5 › Custom › 12.0 Functions in C Language.pdf pdf
Functions in C Language
Government Degree College Beerwah was established in 2005. Started with just one stream and few courses, the college now offers BA, BSC, BCOM, BCA and various Skill Empowerment Courses. The College has had the distinction to have been awarded the NAAC “B” grade in a short span of time.
🌐
I Can Tutorials
icantutorials.com › 2023 › 04 › math.h-C-Math-Library-Functions-and-example-program.html
math.h: C Math Library Functions and example program - I Can Tutorials
STEP 1: START STEP 2: CALL ceil function ceil(number) PRINT “return value of ceil function” STEP 3: CALL floor function floor(number) PRINT “return value of floor function” STEP 4: CALL square root function sqrt(number) PRINT “return value of sqrt function” STEP 5: CALL power function pow(base & exponent) PRINT “return value of pow function” STEP 6: CALL absolute function abs(number) PRINT “return value of abs function” STEP 7: END · #include<stdio.h> #include <math.h> #include <conio.h> int main(){ printf("Demonstration of math.h library functions:"); printf("\nceil(5.3):