Thread: powers

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    1

    powers

    how would you put a number to a power? I know that in a graphing calculator you would do 12^3, but how would you express this in C++? I need to set a variable g to 6.67*10^(-11) which is the universal gravitational constant if any one was wondering :P

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    for x^y, you would use the "math.h" function pow(x, y);
    Devoted my life to programming...

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    pow - C++ Reference


    [edit] Ooooh...not quite quick enough! [/edit]

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I need to set a variable g to 6.67*10^(-11) which is the universal gravitational constant if any one was wondering :P
    Like

    double G = 6.67E-11;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help involving powers and a clock?
    By rllove37 in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2010, 06:10 PM
  2. Sum of User Defined Matrix Powers
    By QuaX in forum C Programming
    Replies: 1
    Last Post: 04-19-2009, 11:33 PM
  3. The powers (that be)
    By mlmoran in forum C Programming
    Replies: 4
    Last Post: 05-02-2007, 12:49 PM
  4. On Women and Their Powers
    By UnregdRegd in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 03-30-2004, 04:55 PM
  5. With super powers would you:
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-17-2003, 11:27 PM