Thread: math function

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    math function

    I need to find the difference in two numbers

    Example ::::

    3 && 6 = 3
    -3 && 6 = 9
    -3 && -6 = 3
    3 && -6 = 9


    Is there a standard math function that dose this, or do i need to write my own?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You can use abs() -

    printf("%d\n%d\n%d\n%d\n",abs(3-6),abs((-3)-6),abs((-3)-(-6)),abs(3-(-6)));
    zen

  3. #3
    Unregistered
    Guest
    int difference(int a, int b)
    {
    return abs(a - b);
    }

    No standard function that I know of. Above is my version. abs() is a standard function that returns the absolute value of the integer in the ()s and is located in math.h. Code has not been tested.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM