Thread: Header

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    9

    Unhappy Header

    Could you tell me what should be the header I have to include in a C code to be possible to use the power function? I mena, I need to use,

    Code:
    pow(x,y)
    whrw
    Code:
    x
    and
    Code:
    y
    are real numbers.

    Thanks.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Code:
    #include <math.h>
    
    int main(void)
    {
       double x = 10;
       double y = 3;
       double z = pow(x, y);
       return 0;
    }

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If by "real number" you mean a float, then powf() is what you're looking for. pow() operates on doubles, and there's another function for long doubles. Generally you can just use pow(), though, for floats and doubles.

    pow*() is in <math.h>. On some systems, you may need to link with the math library to use them; for GCC, add -lm on the command line.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM