In C++ Please,
Write a code fragment that uses a loop to calculate ln (i.e. natural log), from values of ranging from ‘1’ through ‘10’ in steps of ‘1’. Print out in this format:
Ln(1) = 0
Ln(2) = 0.6931
etc.
#include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { cout << "Ln(1) = 0" << endl; cout << setprecision(4) << fixed; for (int i = 2; i <= 10; ++i) { cout << "Ln(" << i << ") = " << log(i) << endl; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.