Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is log() in C?

Umme Ammara

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 log function is a C library function that returns the natural logarithm of an argument.

To use the log function, the math header file needs to be included in the program, as follows:

#include <math.h>

Parameters

The log function takes a single argument of the floating-point type and computes its logarithm to the base of e.

Return Value

If the argument is greater than zero, the log function returns the natural logarithm of the argument in the float type.

  • If the argument is 0, a range error is returned

  • If the argument is less than zero, a domain error is returned

Example

The following code explains the use of log function in C:

#include <stdio.h>
#include <math.h>
int main() {
//Define argument 'x'
double x = 5.1;
//Compute the Log
double answer;
answer = log(x);
//Display the result
printf ("The Log of %f is %f", x, answer);
return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Umme Ammara
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