example3_exponential_log_functions.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <cmath>

int main() {
    double x = 2.0;

    std::cout << "e raised to " << x << ": " << std::exp(x) << std::endl;
    std::cout << "Natural log of " << x << ": " << std::log(x) << std::endl;
    std::cout << "Log base 10 of " << x << ": " << std::log10(x) << std::endl;
    std::cout << "Log base 2 of " << x << ": " << std::log2(x) << std::endl;

    double base = 3.0;
    double value = 27.0;
    std::cout << "Log base " << base << " of " << value << ": " 
              << std::log(value) / std::log(base) << std::endl;

    return 0;
}
Back to cmath