Solution for Exercise 12-4

ex1204

#include <stdio.h>

int main()
{
    int highscore[4];
    int x;

    for(x=0;x<4;x++)
    {
        printf("Your #%d score: ",x+1);
        scanf("%d",&highscore[x]);
    }

    puts("Here are your high scores");
    for(x=0;x<4;x++)
        printf("#%d %d\n",x+1,highscore[x]);

    return(0);
}

Output

Your highest score: 750
Your second highest score: 699
Your third highest score: 675
Your fourth highest score: 666
Here are your high scores
#1 750
#2 699
#3 675
#4 666

Notes

* The x+1 trick doesn't change the value of x, which is used in the loops as well as to reference each array element. No, this expression allows a human number to be output. You use that trick often when you plow through arrays.