From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Working with arrays

Working with arrays

- [Instructor] In This code, float array highscore has five elements. Lines seven through 11 set the array element values. Each element referenced like an individual float variable. Likewise in lines 14 through 18, each element of the array is used as an individual float variable, but they're repetitive, which really isn't a good thing, not a good programming practice. The code can be streamlined by adding a loop. Looping variable must be declared, and the for loop would go right after this puts statement. For (x=0), the first element of the array is zero. This loop will repeat five times. Now modify the printf statement to output the values and get rid of these. The number also needs to be addressed. And for the number output, I'm going to use x+1, because remember, x starts at zero. Let's run the code to make sure it all works. And there are the five values. When I look at the code, more streamlining is possible. The assignments can be made when the array is declared. They don't…

Contents