Solution for Exercise 8-10

ex0810

#include <stdio.h>

int main()
{
    int a,b;

    a = 6;
    b = a - 2;

    if( a > b)
    {
        printf("%d is greater than %d\n",a,b);
    }
    else
    {
        printf("%d is not greater than %d\n",a,b);
    }
    return(0);
}

Notes

* Line 16 doesn't print "is less than" because that isn't the logical conclusion. The value can be less than, but also could be equal to. The phrase "is not greater than" is the proper conclusion.

* You don't need to use curly brackets when only one statement follows if. That rule also holds for the else part of the structure: When only one statement follows else, you can dispense with the curly brackets.

* By the way, each part of the structure is unique. So you can have multiple statements belonging to if — in which case you need the curly brackets — but if the else part has only one statement, you don't need curly brackets.