Thread: Square Root

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Square Root

    How would I get the square root in C++, do I have to use a function or something? I am using it for A*A + B*B = C*C, but I want to square root C so it is just C (this is the Pythagoreum Therom if I am not mistaken, except that it uses square root signs, the little 2s, but I don't know how to make them ). Any help is appreciated and needed.

  2. #2
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Lightbulb

    Yeah there's a function for that:

    Prototype: double sqrt(double num);
    Header file: math.h

    PHP Code:
    /*Start of code*/

    #include <math.h>
    #include <iostream.h>

    int main(void
    {
      
    double num 9.0;

      
    cout << "The square root of " << num << "is " << sqrt(num);
      return 
    0;
    }

    /*End of code*/ 
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    Great, thanks tons. That will help me out alot.
    "Um...well..."
    -Kyoto Oshiro

  4. #4
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225
    Sure! Any time
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    79
    You could also use this:
    double pow(double x,double y);
    It raises x to the power of y, and returns the result.
    Include math.h
    e.g. pow(number,0.5);

  6. #6
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225
    Yeah that too
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program to calculate the square root
    By saszew in forum C Programming
    Replies: 7
    Last Post: 10-28-2008, 12:53 PM
  2. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. Square Root ?!?
    By Tm687 in forum C++ Programming
    Replies: 1
    Last Post: 02-29-2004, 04:38 PM
  5. Templated Binary Tree... dear god...
    By Nakeerb in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2003, 02:24 AM