log10() in C: Base-10 Logarithm

log10() returns the base-10 logarithm of a positive value. It answers questions such as “10 raised to what power gives this number?”

Syntax Top ↑

double log10(double x);

Powers of Ten Top ↑

#include <math.h>
#include <stdio.h>

int main(void) {
    printf("log10(1000) = %.1f\n", log10(1000.0));
    return 0;
}

Output

log10(1000) = 3.0

Number of Decimal Digits Top ↑

#include <math.h>
#include <stdio.h>

int main(void) {
    unsigned int value = 54321;
    int digits = (int)floor(log10((double)value)) + 1;

    printf("Digits: %d\n", digits);
    return 0;
}

This shortcut applies only to positive integers. Handle zero separately if adapting it for general input.





plus2net.com






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