Solution for Exercise 6-6

ex0606

#include <stdio.h>

#define GLORKUS 16

int main()
{
    int blorf;

    blorf = 22;

    printf("The value of blorf is %d.\n",blorf);
    printf("The value of blorf plus 16 is %d.\n",blorf+GLORKUS);
    printf("The value of blorf times itself is %d.\n",blorf*blorf);
    return(0);
}

Notes

* The above solution is okay, but the following solution is better:

#include <stdio.h>

#define GLORKUS 16

int main()
{
    int blorf;

    blorf = 22;

    printf("The value of blorf is %d.\n",blorf);
    printf("The value of blorf plus %d is %d.\n",GLORKUS,blorf+GLORKUS);
    printf("The value of blorf times itself is %d.\n",blorf*blorf);
    return(0);
}

* In Line 12, the value of GLORKUS is shown immediately in the printf() funciton by using the %d conversion character. I highly recommend this solution as it allows you to change the constant later without having to search through the code and look for any immediate references to its value.