How to calculate log10 (base-10 logarithm) in C

1 Answer

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

//  double log10(double x);
 
int main(int argc, char **argv) 
{
    printf("%.2f\n",  log10(123));
    printf("%d\n",  (int)log10(123));
    printf("%.2f\n",  log10(1234));
    printf("%d\n",  (int)log10(1234));
    printf("%.2f\n",  log10(12345));
    printf("%d\n",  (int)log10(12345));

    return(0);
}
 
 
/*
run:
 
2.09
2
3.09
3
4.09
4
 
*/

 



answered Dec 13, 2015 by avibootz

Related questions

2 answers 338 views
3 answers 349 views
1 answer 178 views
178 views asked Feb 8, 2020 by avibootz
...