Reputation: 119
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
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
Reputation: 51245
#include <math.h>
double function(double x)
{
double y = 20 * log(x + 3.0);
return y;
}
Upvotes: 2
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
Reputation: 6066
The log function in the c library is performs a natural logarithm ('ln'). See this for more details: CPlusPlus - log
Upvotes: 1
Reputation: 28137
double myfunction(int x){
return (20* log(x+3) );
}
?
And you call it :
double y = myfunction(yourX);
Upvotes: 3