math function

This is a discussion on math function within the C++ Programming forums, part of the General Programming Boards category; I need to find the difference in two numbers Example :::: 3 && 6 = 3 -3 && 6 = ...

  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
    zen
    zen is offline
    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, 02:07 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 12: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, 12:03 PM
  5. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM

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