On Wed, Oct 29, 2008 at 11:20 PM, Olufowobi Lawal <[EMAIL PROTECTED]> wrote:
> I had just started learning C and just joined the group.
>
> Presently I am reading the book "sams teach yourself C in 24hrs 2nd ed"
>
> The below source code is from page 151 of the book, I compiled it (using
> plato) but it gave me an error.
> I noticed that the sqrt function referred to nothing.
> But in the book it compiled successfully and the printed output was correct.
>
> so my question is; was the author mistaken & are there such similar errors
> in the
> book (for those who have read it before)?
I suspect it's not the author, but the publishers. But the author
doesn't help themselves...
> Or is my compiler the problem.
Not heard of your compiler.
> Also is it possible to run C codes on Microsoft visual Studio C++
Yes. In fact, if you can run the latest version, you are advised on
this list to do so.
> #include<stdio.h>
> #include<math.h>
> main()
It's either an old book, or the author doesn't know what they're
talking about with respect to compatibility between compilers (or The
C Standard.) That should be:
int main(void)
> {
> double x,y,z;
> x=64.0;
> y=3.0;
> z=0.5;
>
> printf("pow(64.0,3.0) returns: %7.0f\n",pow(x,y));
> printf("sqrt(64.0) returns: %2.0f\n",sqrt);
Looks like a typo to me. There should be a (64.0) after the last sqrt
in that statement.
(Detail you probably don't want: what the statement you actually
posted does is pass the address of the function (as opposed to the
result of calling the function with a parameter) and it interprets it
as a float. Certainly not what you want to be doing.)
> printf("pow(64.0,0.5) returns: %2.0f\n",pow(x,z));
> return 0;
> }
>
>
> N.B
> There is something similar in pg 150 of the same book
> printf("The cosine of 45 is : %f.\n",cos);
Another typo. Slightly worse actually - cos() (and associated
functions) take their parameter in radians. The string in the printf()
looks to be in degrees.
--
PJH
http://shabbleland.myminicity.com/ind