Exponential In C

Exponential in C Programming

In C programming, we calculate the exponential value of Euler's number, denoted by the constant e. The numerical value of e is roughly 2.71828. This computation is facilitated by the exp function which is declared in the maths.h header file. Therefore, when ```

Double exp(double parameter);

Example


### Syntax of exp() function in C Programming

Double exp(double parameter);

Example


### Parameter for exp() function

The function solely needs a single parameter, which will hold the value for raising e to a specific power. This exponent value remains constant throughout the computation process.

### Return Type for exp() function

The exp() function returns a double data type, which can also be a float or any suitable numeric data type capable of storing the value.

### Implementing exp() function in C Program

Below is the code snippet demonstrating the implementation of the exp() function in a C program.

//Include the maths header file in the program.

include <stdio.h>

include <math.h>

int main

{// Use the exp function to compute the exponential value for e.

printf("The value for e raised to power 0 is = %.6f \n", exp(0));

printf("The value for e raised to power 2 is = %.6f \n", exp(2));

printf("The value for e raised to power 13 is = %.6f \n", exp(13));

printf("The value for e raised to power 12.01 is = %.6f \n", exp(12.01));

printf("The value for e raised to power -1 is = %.6f \n", exp(-1));

printf("The value for e raised to power -3.73 is = %.6f \n", exp(-3.73));

// Using .6f to print the result will return the answer up to 6th decimal place.

return 0;

}

Example


Output:

[Program Output]

Example


### User Input for Computing the Exponential Value

//The C Program for raising the power of e by user input

//exp is defined in math.h header file

include <stdio.h>

include <math.h>

int main

{

float power, result;

printf(" Please input the value to raise e : \n");

//take user input

scanf("%f", &power);

//Store answer

result = exp(power);

printf("\n The value for e raised to the power %.4f is = %.6f \n", power, result);

return 0;

}

Example


Output:

[Program Output]

Example


In the example provided, user input is received to obtain a floating-point value. This value, entered by the user, will be utilized for calculating the exponentiation within the program and then assigned to the variable named result. Subsequently, the result will be outputted in the final statement, displaying the answer accurate to six decimal places.

Input Required

This code uses input(). Please provide values below: