Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gusious

macrumors 65816
Original poster
Dec 2, 2007
1,277
2
Greece
Hi.This is a bit urgent....

I am writing a program in C and i need to insert ln(natural logarithm).How do i do that?
 
That's what i have inserted but i have this message: error: invalid lvalue in assignment

What's that?Oh,should i declair the value ln(number) which is ln(pi)+=log(pi) as float?
 
I think your problem is that ln(pi) is not a variable; thus, you can't use it on the left side of an assignment.

I think what you want is:

double result;
result = log(pi)+log10(pi); //assigns the result of ln(pi) plus log(base ten)(pi) to result.
 
You use log(x) to calculate the natural logorithm of x. C is like mathematicians, who use log to mean the natural log rather than ln.

see man math on the command line for this information.
 
No i don't need log.I only need ln.Wait a sec.Or more.I had an idea...

Check this out:

#include <stdio.h>
#include <math.h>

main()
{
float H,pi;
int n,ni,i,x[1000],y[1000],points;


points=0;
printf("insert ni and n\n");
while(scanf(" %d %d ",&ni,&n) ==2)
{
x[points]=ni;
y[points]=n;
points++; }
pi=0;
H=0;
for(i=0; i<points; i++)
{
pi= pi + x/y;
}

H=-(pi*ln(pi));
printf("The pi is %f,the ln(pi) is %f and the H is %f\n",pi,ln(pi),H);
}

I want to calculate the sum pi*ln(pi).So,can you find me the problem?
 
Listen to Eraserhead

Change ln(...) to log(...) like he said. If you're not satisfied with his answer then try it and then double check it with your calculator...

Nuc
 
Change 'ln' to 'log'.

In programming log(N) is the natural log of N.

Of course the program will never end unless you error it somehow. Glad I never wasted time "learning" programming in school. I wonder how anyone gets anywhere at first.
 
Check this out:

#include <stdio.h>
#include <math.h>

main()
{
float H,pi;
int n,ni,i,x[1000],y[1000],points;


points=0;
printf("insert ni and n\n");
while(scanf(" %d %d ",&ni,&n) ==2)
{
x[points]=ni;
y[points]=n;
points++; }
pi=0;
H=0;
for(i=0; i<points; i++)
{
pi= pi + x/y;
}

H=-(pi*ln(pi));
printf("The pi is %f,the ln(pi) is %f and the H is %f\n",pi,ln(pi),H);
}

I want to calculate the sum pi*ln(pi).So,can you find me the problem?


I see you've got it now...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.