log function
Related library: math.hThe log function returns the natural logarithm (base e) of number.
Usage
| double log(double number) |
Input Parameters
Where
number is the number that will be calculated.
Return Value
The log function returns the logarithm of number.
If number is negative, log will return NAN and will set errno to EDOM.
If number is 0, log will return -INFINITY and will set errno to EDOM.
If number is NAN, log will return NAN.
If number is INFINITY, log will return INFINITY.
Example
#include <stdio.h>
#include <math.h>
int main()
{ double input; double output;
printf("Please enter a double: "); scanf("%lf", &input);
if(input <= 0) { printf("Logarithm does not return an integer for numbers <= 0"); return 1; }
output = log(input);
printf("The logarithm of %f is %f\n", input, output);
return 0;
}
|
History
We have no records of the history of this function. Know a source? Contact us.
Notes and Warnings
Understanding the Example Code
- Ask user for a number.
- Check if the number is less than or equal to 0. If so, send an error.
- Find the logarithm of the number, and output the results.
Example Runs
Please enter a double: 1
The logarithm of 1.000000 is 0.000000
Please enter a double: 2.71828183
The logarithm of 2.718282 is 1.000000
Please enter a double: -1
Logarithm does not return an integer for numbers <= 0
|

Er zijn nog geen reacties geplaatst!
Je bent niet ingelogd! Meld je
hier aan of log je aan de rechterkant in!