Hello to everyone,I'm using a Borland BCC55 compiler to describe the logarithm function.
It works fine,but only with numbers higher than 1,if I insert any floating point the result stucks on -46,whatacer number <1 I write.
Here is the function,I made it myself (on a text host):
http://freetexthost.com/kv0rdi4gno
Of course I have to do it with only the stdio.h library,no math.h or it's like cheating.
Anyone explain me why I get this "-46" and how to fix it?
Here's the image,please help me !!
http://img28.imageshack.us/img28/5259/catturados.png

Post your code here instead of posting a link on some other computer -- which would not respond when I tried to read it. Just simply copy and paste the code in your post and surround it with [code] ... [/code] code tags.

#include<stdio.h>
int logaritmosup(int,int);
int logaritmoinf(int,int);
main()
{
float c;
scanf("%f",&c);
if(c>=10.0)
printf("%d\n",logaritmosup(10.0,c));
else
printf("%d\n",logaritmoinf(10.0,c));
return 0;
}
int logaritmosup(int m,int n)
{
float i,p;
p=0.0;
for(i=m;i<=n;i=i*10.0)
++p;
return p;
}
int logaritmoinf(int m,int n)
{
float i,p;
p=1.0;
for(i=m;i>n;i=i/10.0)
--p;
return p;
}

If anyone explains me why I get -46 as result of log of 0.1 I would be glad,I'm really going crazy on it xD

What happens when you compare the float i with the int n? That seems to be the only place where it could be going wrong.

I suggest that you instrument after line 26 with printf("m=%d, n=%d, i=%f, p = %f\n",m,n,i,p); . You might also want to print out the boolean that is the stop condition. Be sure to add curly braces around the body of the loop.

I am pretty sure that you are mixing types as griswolf has noted.

Edited 6 Years Ago by mcodesmart: n/a

you are passing a floating point value as an int..

try this:
line 3
int logaritmoinf(int,float);
line 22
int logaritmoinf(int m, float n)

it worked for me..

This question has already been answered. Start a new discussion instead.