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);
}
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, that equation allows a human number to be displayed. You'll use that trick often when you plow through arrays.
* The & operator is still required by scanf() to read values into an array element. Each array element is essentially an individual variable. The & operator doesn't really care whether the variable is part of an array or floating off in memory somewhere.
Copyright © 1997-2025 by QPBC.
All rights reserved
