# This dude need someones help, bad????

Printable View

• 07-12-2002
correlcj
This dude need someones help, bad????
Hello again,

I cant seem to get the forth root to execute properly. Eg; at int 3 the square should read 1.732050808 and the forth root should read 1.316074013. Now my squares are fine but the forth roots aren't. What is wrong in my program and how can i fix it quickly.
Thanx,

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

void prn_heading (void);
void prn_and_read_data (void);

int main()
{
prn_heading();
prn_and_read_data();
return 0;
}

void prn_heading(void)
{
printf("%3s%28s%28s%28s",
"Integer", "Square Root", "Fourth Root\n",
"--------------------------------------------------------------\n\n");
return;
}

void prn_and_read_data (void)
{
int x;
double square_root, fourth_root;

for (x = 1; x <= 100; ++x)
printf("%5d:%28.9e %28.9e\n", x = x, sqrt(x), square_root = pow(x, x));
fourth_root = square_root * square_root;
printf("%50.9e", fourth_root);
;
return;
}
• 07-12-2002
Unregistered
I haven't done any math since school, but i believe that the problem is in how you create your fourth root. Multiplying the square root by itself is giving you the first number again, not the fourth root. For example- the square root of 4 is 2. 2*2 equals 4, not 1.7 something. Try something else. I believe that dividing the square root by the first number will work.
• 07-12-2002
correlcj
math student...
Hello,
when i started the program i too could not believe it but somewhere in the code maybe...i donno.
anyway another question i had is when i ran it after compiling all the forth root numbers were exactly the same... sounds wierd huh?
can you please explain why?
:D
• 07-12-2002
Draco
did it do that with or without the changes? Just to let you know, you shouldn't need to write x=x, you should be able to just use x in the display argument.
• 07-12-2002
correlcj
draco
If i axe x = x then it prints it onto the scree haphazardly. I tried what you said by placing it in the argument stream but on the visual C++ software that what i got.

Now my fourth root does not print with any changes, its something like 2.65 all the way down. weird huh?
I am sure my math is correct but like the old west says " i aint no math want to be player!"
just kidding... no sense to be made there!
:p
• 07-12-2002
*ClownPimp*
x^(1/4) = x^(1/2 * 1/2) = (x^(1/2))^(1/2)

fourth_root = sqrt( sqrt(x) );
• 07-12-2002
correlcj
hello there pimppy!
Hello,
your close but no dice. The program when you run it should read:

integer sq rt fth rt
1 1.00000000 1.00000000
2 1.414213562 1.189207115
3 1.732050808 1.316074013
4 2.00000000 1.414213562

Thanks for trying to help me out. If you can still try i would appreciate it.
Keep pimpin'
:p
• 07-12-2002
*ClownPimp*
this works

printf("%.9lf\n", sqrt(sqrt(2.)));

just modify this to suit your needs
• 07-12-2002
correlcj
like this?
Do you mean like this?
Because its still not working, Mr. Pimp.
Thanks anyways but if you can get it to work, please let me know, sir.
It does complie and run but the figures are way off and i am starting to wonder whoever wrote this damn book was probably way off to start with.
Thanks!

void prn_and_read_data (void)
{
int x;
double square_root, fourth_root;

for (x = 1; x <= 100; ++x)
printf("%5d:%28.9e %28.9e\n", x = x, sqrt(x), square_root = pow(x, x));
fourth_root = sqrt( sqrt(x) );
printf("%50.9lf\n", sqrt(sqrt(2.))); /*inserted here*/
;
return;
}

:cool:
• 07-12-2002
*ClownPimp*
why do you have that extra printf at the end? You need to take out 'square_root = pow(x, x)' and replace that with 'square_root = sqrt( sqrt (x) )'.

Also, your control string (or whatever its called) is screwed up. What I meant for you to do is change the control string in the printf thats inside the for-loop:

"%5d:%28.9e %28.9e\n", --> "%d %.9lf %.9lf\n"