Solution for Exercise 12-3
ex1203
#include <stdio.h> int main() { int highscore[4]; printf("Your highest score: "); scanf("%d",&highscore[0]); printf("Your second highest score: "); scanf("%d",&highscore[1]); printf("Your third highest score: "); scanf("%d",&highscore[2]); printf("Your fourth highest score: "); scanf("%d",&highscore[3]); puts("Here are your high scores"); printf("#1 %d\n",highscore[0]); printf("#2 %d\n",highscore[1]); printf("#3 %d\n",highscore[2]); printf("#4 %d\n",highscore[3]); return(0); }
Notes
* The array is declared at Line 5. It's named highscore
and it has room for 4 elements.
* The scanf() statements fill each value of the highscore
array. The elements are numbered in the square brackets, 0
through 3
. Yes, that's four items, which explains the 4 on Line 5.
* Lines 17 through 20 display the highscore
array's elements, 0
through 3
. Each array element is referenced just like an individual int variable.
Copyright © 1997-2024 by QPBC.
All rights reserved