Thread: help with mathematical problem in C

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

    help with mathematical problem in C

    HI,

    i am new to this forum and C language too. This actually is my first post. I need help with performing this mathematical operation in C.

    B(X5 + Y3 + Z3)/7 where X,Y,Z are input data from the keyboard and B=4.

    PLS, X5,Y3,Z3 implies X raised to the power of 5, Y raised to the power of 3 and Z raised to the power of 3.

    Hope to hear from someone soon.

    Thanks.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    multiplication is done with *, exponentiation with the function pow.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > X5
    Write
    pow(X,5)

    > B(X5
    Would be
    B * ( pow(x,5)

    Just have
    #include <math.h>
    and see what you can come up with.
    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.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You may also have to link with the math library; for GCC, add -lm to the end of the command line.
    Code:
    $ cat 2pow20.c
    #include <stdio.h>
    #include <math.h>
    
    int main(void) {
        double x = 2.0, y = 20.0;
    
        printf("%f\n", pow(x, y));
    
        return 0;
    }
    
    $ gcc -W -Wall -ansi -pedantic -O2 2pow20.c -o 2pow20 -lm
    $ ./2pow20
    1048576.000000
    $
    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. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Mathematical, nautical steering problem
    By Warlax in forum Game Programming
    Replies: 6
    Last Post: 06-16-2006, 06:01 PM
  4. Mathematical problem
    By Warlax in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2006, 02:38 AM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM