powers

This is a discussion on powers within the C++ Programming forums, part of the General Programming Boards category; how would you put a number to a power? I know that in a graphing calculator you would do 12^3, ...

  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
    1,602
    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,786
    pow - C++ Reference


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

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 05: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, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21