I'm trying to learn how to calculate the logarithm base 10 of any numbers that I enter via scanf to my code. I figure that I could calculate the ln(a) a being the number input. I have a working code that calculates this; however now i just want to divide any numbers that my ln(a) code outputs by the defined LN10. This is because the natural log of a number divided by the natural log of 10 will output my required log base 10 value that I am working to achieve. Here is the mess I have at the moment. Any help is extremely appreciated!
#define _CRT_SECURE_NO_WARNINGS
#define ALMOSTZERO 0.0000000000000000001
#define LN10 2.3025850929940456840179914546844
#include <stdio.h>
double log10(double);
double ln(double);
void main()
{
{
double x, a;
printf("Enter value: ");
scanf("%lf", &x);
while (x > 0)
{
double log10 = ln(x) * LN10;
printf("log10(%lf)=%lf\n", x, a);
printf("Enter value: ");
scanf("%lf", &x);
}
}
}
double ln(double x)
{
double sum = 0.0;
double xmlxpl = (x - 1) / (x + 1);
double denom = 1.0;
double frac = xmlxpl;
double term = frac / denom;
while (term > ALMOSTZERO)
{
sum += term;
//generate next term
denom += 2.0;
frac = frac * xmlxpl * xmlxpl;
term = frac / denom;
}
return 2.0 * sum;
}