
- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library - exp() function
The C library exp() function of type double accept the single parameter(x) that returns the value of exponent raised to the base power.
In mathematics, an exponent is a small integer that positioned in the upper right of a base number.
Syntax
Following is the syntax of the C library function exp() −
double exp(double x)
Parameters
This function accepts only a single parameter −
x − This is the floating point value.
Return Value
This function returns the exponential value of x.
Example 1
The C library program shows the usage of exp() function.
#include <stdio.h> #include <math.h> int main () { double x = 0; printf("The exponential value of %lf is %lf\n", x, exp(x)); printf("The exponential value of %lf is %lf\n", x+1, exp(x+1)); printf("The exponential value of %lf is %lf\n", x+2, exp(x+2)); return(0); }
Output
On execution of above code, we get the following result −
The exponential value of 0.000000 is 1.000000 The exponential value of 1.000000 is 2.718282 The exponential value of 2.000000 is 7.389056
Example 2
Below the program demonstrate the usage of exp() in a for loop.
#include <stdio.h> #include <math.h> int main() { printf("Exponential Series (e^x) for x from 1 to 10:\n"); for (int x = 1; x <= 10; ++x) { double result = exp(x); printf("e^%d = %.6lf\n", x, result); } return 0; }
Output
After executing the above code, we get the following result −
Exponential Series (e^x) for x from 1 to 10: e^1 = 2.718282 e^2 = 7.389056 e^3 = 20.085537 e^4 = 54.598150 e^5 = 148.413159 e^6 = 403.428793 e^7 = 1096.633158 e^8 = 2980.957987 e^9 = 8103.083928 e^10 = 22026.465795
Example 3
In this program, it illustrates how to use exp() to find (e^x), where (x) is any real number.
#include <stdio.h> #include <math.h> int main() { double x = 3.0; double result = exp(x); printf("e raised to the power %.2lf = %.2lf\n", x, result); return 0; }
Output
The above code produces the following result −
e raised to the power 3.00 = 20.09