Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 7th, 2004, 5:03 PM   #1
emdiesse
Programmer
 
Join Date: Jul 2004
Location: Hampshire
Posts: 56
Rep Power: 5 emdiesse is on a distinguished road
How would i work out the squareroot of a number in C++?
Example:
The number is 25, how would i work out the sqareroot of 25 is 5 using C++?
emdiesse is offline   Reply With Quote
Old Oct 7th, 2004, 5:09 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
#include <math.h>

int main(void)
{
  .........
   .........
 ...............
  double x = sqrt(25);
}

I think that should work.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 7th, 2004, 5:28 PM   #3
emdiesse
Programmer
 
Join Date: Jul 2004
Location: Hampshire
Posts: 56
Rep Power: 5 emdiesse is on a distinguished road
Thank you

I'm attempting to learn C++

I have decided i would make a program to work out quadratic formula questions.

I'm getting there slowly
emdiesse is offline   Reply With Quote
Old Oct 7th, 2004, 6:51 PM   #4
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4 Benoit is on a distinguished road
I'm always making math programs in C.....I really need to make one that assists in my accounting homework
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Oct 7th, 2004, 11:19 PM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
My professor called the square root function "squirt".... He also referred to gigabytes as "bubbabytes" I guess its a southern thing .

sqrt() will get what ya need.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Oct 8th, 2004, 5:24 AM   #6
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 550
Rep Power: 4 Benoit is on a distinguished road
Our computer engineering teachern's name is Mr. Festchyn....We sometimes call him F Diddy B) Last year we had an electronic scrolling sign and it said 'F Diddy is the shiz'
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Oct 9th, 2004, 7:42 AM   #7
Ashcroft
Programmer
 
Join Date: Sep 2004
Posts: 38
Rep Power: 0 Ashcroft is on a distinguished road
If you just want the answer then use the math.h function, if you are interested in how to actually determine the square root of a number you should do a google search of "newton's method" and "square root" - writing a program that does this is one of those rites of passage you will probably do in your CS courses eventually.
Ashcroft is offline   Reply With Quote
Old Oct 9th, 2004, 9:01 AM   #8
Leonas
Newbie
 
Join Date: Oct 2004
Posts: 8
Rep Power: 0 Leonas is on a distinguished road
Quote:
Originally posted by Ashcroft@Oct 9 2004, 12:42 PM
If you just want the answer then use the math.h function, if you are interested in how to actually determine the square root of a number you should do a google search of "newton's method" and "square root" - writing a program that does this is one of those rites of passage you will probably do in your CS courses eventually.
I think you can also go into the Math.h file and see how they did it instead of google searching the information. Im not sure if that would work but I think it is possible.
Leonas is offline   Reply With Quote
Old Oct 9th, 2004, 10:18 AM   #9
Ravilj
Programmer
 
Ravilj's Avatar
 
Join Date: Sep 2004
Location: JHB , South Africa
Posts: 79
Rep Power: 4 Ravilj is on a distinguished road
I doubt that, I would bet its coded in assembler. You would be able to see the definition of the function but thats about it :/
__________________
Ravilj's OpenGL Terrain aka WinTerrain Last Updated: 17/01/2005!
Ravilj is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:33 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC