Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is exp in C?

Hassaan Waqar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The exp function is part of the <math.h> header file. It is equivalent to an exponent in mathematics. The function takes in a single parameter: a double value. It then raises it to the power of e and returns the resultant double value.

exp(2) = e2e^2

The illustration below shows how exp works:

How does exp work

Declaration

The exp function is defined as follows:

double exp(double x);

It takes in a single parameter of type double.

Example

The following code snippet shows how we can use the exp function. The code below outputs the exponent of the number in the parameter:

#include <stdio.h> // Including header file for printf function
#include <math.h> // Including header file for exp function

int main(){

  double num = 5.0; // assign value to number
  double result; // variable to store result
  result = exp(num); // taking exponent of number
  printf("The exponent of %.2lf is: %.2lf", num, result);
  return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Hassaan Waqar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring