Math Help

This is a discussion on Math Help within the C Programming forums, part of the General Programming Boards category; Ok, I am supposed to add some brackets to this equation: 5 + 3 * 8 / 2 + 2 ...

  1. #1
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    Math Help

    Ok, I am supposed to add some brackets to this equation:
    5 + 3 * 8 / 2 + 2
    So that it will equal 16, but I can't seem to get it, the closest I have come is 16.5 and 17, this question is from Sams Teach Yourself C Programming in 21 Days, I got it off of the net but I couldn't get the appendix because the site shut down, can someone help me here, it isn't necessary because I am not in a class but it is bothering me like you wouldn't believe. Not to mention headaches and screaming children, so if you would please
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Don't forget the rules of operations. Mul and div are higher than add and sub when read in the same expression.

    Code:
    #include <stdio.h>
    
    int main(void)
    {
         int result;
         
         result = (5 + 3) * (8 / (2 + 2));
         
         printf("%d", result);
    
         return 0;
    }
    If it's 16 you need, then it's 16 you get.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  3. #3
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Well i'll be damned Ronin, thanks.

    Although trust me I know all about the order of operatoins, we only did it for about a good month or so in math . Although I am still working on learning all of C's operaters and where they stand, but that would be why the question is there because that is what part of the chapter was working on, and thanks again that was driving me nuts.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math
    By knightjp in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 05:36 PM
  2. Help with C++ Math
    By aonic in forum C++ Programming
    Replies: 4
    Last Post: 01-29-2005, 03:40 AM
  3. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 02:14 AM
  4. Math Header?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 09-17-2004, 06:39 AM
  5. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 09:06 PM

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