Results 1 to 3 of 3

Thread: math operators

  1. #1

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    Hihi. I'm in the middle of learning C++. Can any of you tell me how to get the square root of something? Like, in VB, you put Sqr(numberGoezHere). how do you do that in C++? and then, how do you raise something to a power?
    To understand recursion, one must first understand the concept of recursion.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The mathematical functions are in math.h, but if you're using the Standard Library (like most of us ), they're then in cmath:
    Code:
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    void main() {
        double x = 5;
    
        cout << sqrt(x) << endl;
    }
    To raise to a power, use pow.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    kewl, thanks ^^
    To understand recursion, one must first understand the concept of recursion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width