r/cprogramming • • Jul 05 '22

What's wrong with my program, I get nothing in the end :/

2 Upvotes

10 comments sorted by

3

u/shut_up_if_your_dumb Jul 05 '22

The function ln(x) returns the solution but you are ignoring the return value. You can use printf to see the return value like this:

printf("%f", ln(x));

4

u/[deleted] Jul 05 '22

Oh yes, I forgot. Thank you.

1

u/[deleted] Jul 05 '22

Also, regarding the first photo and solution part, the sequence for increasing exponent of (x-1) is omitted, right?

1

u/sidewaysEntangled Jul 05 '22

No, see where factor is *= each loop. That is accumulating the exponent.

1

u/[deleted] Jul 05 '22

Wouldn't that mean factor * (x -1)?

1

u/sidewaysEntangled Jul 05 '22

*= means factor = factor * (x-1) So each time through, it scales by another x-1

1

u/[deleted] Jul 05 '22

Understand :)

10

u/sk3tChY21 Jul 05 '22

Your ln function returns the answer but you aren't storing it in a variable or printing it to the screen.

3

u/Kayin-Chu Jul 05 '22 edited Jul 05 '22

you called the function, but not printed its return value.

printf("result : lf\n", ln(x));

or

double result = ln(x);
printf("result : lf\n", result);

1

u/shut_up_if_your_dumb Jul 05 '22

Was probably a typo but you should use double the result variable