w3resource

C exp() function

C exp() function - Calculate exponential function

Syntax:

double exp(double x)

The exp() function is used to calculate the exponential value of a floating-point argument x ( ex , where e equals 2.17128128...).

Parameters:

Name Description Required /Optional
x The floating-point value to exponentiate the natural logarithm base e by. Required

Return value from exp()

  • Upon successful completion, these functions shall return the exponential value of x.

Example: exp() function

The following example shows the usage of exp() function.

#include <math.h>
#include <stdio.h> 
int main(void)
{
   double x, y;
 
   x = 5.0;
   y = exp(x); 
   printf("exp( %lf ) = %lf\n", x, y);
   x = 4.0;
   y = exp(x); 
   printf("\nexp( %lf ) = %lf\n", x, y);
   x = 3.0;
   y = exp(x); 
   printf("\nexp( %lf ) = %lf\n", x, y);
} 

Output:

exp( 5.000000 ) = 148.413159

exp( 4.000000 ) = 54.598150

exp( 3.000000 ) = 20.085537

C Programming Code Editor:

Previous C Programming: C tanh()
Next C Programming: C frexp()



Follow us on Facebook and Twitter for latest update.

C Programming: Tips of the Day

What's the point of const pointers?

const is a tool which you should use in pursuit of a very important C++ concept:

Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.

Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:

void foo(int* ptr)
{
    ptr = 0;// oops, I meant *ptr = 0
}

If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.

Ref : https://bit.ly/33Cdn3Q