Birdkingz
Birdkingz

Reputation: 119

Need help in doing math calculation for natural logarithm (ln)

How do I write a function for this in C language?

y = 20 ln (x + 3) ?

How do I write the ln function?

Upvotes: 3

Views: 12273

Answers (5)

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361264

#include <math.h> 

double fun(double x)
{
    return 20 * log( x + 3 );  //base-e logarithm!
}

//usage
double y = fun(30);

For base-10 logarithm, use log10().

Upvotes: 12

ronag
ronag

Reputation: 51245

#include <math.h>
double function(double x)
{
     double y = 20 * log(x + 3.0);
     return y;
}

Upvotes: 2

Stephen Canon
Stephen Canon

Reputation: 106117

Although the question is tagged C++, questioner is asking for a C implementation:

#include <math.h>

double myFunction(double x) {
    return 20.0 * log(x + 3.0);
}

Upvotes: 1

DeusAduro
DeusAduro

Reputation: 6066

The log function in the c library is performs a natural logarithm ('ln'). See this for more details: CPlusPlus - log

Upvotes: 1

XCS
XCS

Reputation: 28137

double myfunction(int x){
    return  (20* log(x+3) );
}

?

And you call it :

double y = myfunction(yourX);

Upvotes: 3

Related Questions