How to use log10() function to calculate the common base-10 logarithm in C++

1 Answer

0 votes
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	cout << "log10(1) = " << log10(1) << endl;
	cout << "log10(5) = " << log10(5) << endl;
	cout << "log10(100) = " << log10(100) << endl;
	cout << "log10(125) = " << log10(125) << endl;
	cout << "log10(125) / log10(5) = " << log10(125) / log10(5) << endl;
	cout << "log10(3.5) = " << log10(3.5) << endl;
	cout << "log10(1000) = " << log10(1000) << endl;
	cout << "log10(0.001) = " << log10(0.001) << endl;

	return 0;
}

/*
run:

log10(1) = 0
log10(5) = 0.69897
log10(100) = 2
log10(125) = 2.09691
log10(125) / log10(5) = 3
log10(3.5) = 0.544068
log10(1000) = 3
log10(0.001) = -3

*/

 



answered Mar 26, 2016 by avibootz

Related questions

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