log10() : log of a number to the base 10

#include <stdio.h>
int main() {
printf("\nNumber = %.2f", log10(3.54)); // Number = 0.55
printf("\nNumber = %.2f", log10(-3.12)); // Number = nan
printf("\nNumber = %.2f", log10(10)); // Number = 1.00
printf("\nNumber = %.2f", log10(-1));// Number = nan
printf("\nNumber = %.2f", log10(0));// Number = -inf
return 0;
}
We will get log value of any number with base 10 by using log10() function.
log10(x) 
x = input number

Example

#include <stdio.h>
#include <math.h>
int main(void){
     double  x,ret;
     x=2.7;
     ret=log10(x);
     printf("log10(%.2f)=%.2f", x,ret);
     return 0;
}
The above code will give this output.
log10(2.70)= 0.43

Example: Base-10 Logarithm of Positive and Edge Case Values

Shows how to calculate base-10 logarithms of numbers.
#include <stdio.h>
#include <math.h>

int main() {
    double num1 = 1000.0;
    double num2 = 1.0;
    double num3 = 0.0;
    double num4 = -5.0;

    printf("log10(1000) = %.2f\n", log10(num1));  // Output: 3.00
    printf("log10(1) = %.2f\n", log10(num2));     // Output: 0.00
    printf("log10(0) = %.2f\n", log10(num3));     // Output: -inf
    printf("log10(-5) = %.2f\n", log10(num4));    // Output: nan
    return 0;
}
Output
log10(1000) = 3.00
log10(1) = 0.00
log10(0) = -inf
log10(-5) = nan


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com






    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer