Array Maximum in C
Level 3129 keystrokes
Finds the maximum value in an array using a loop.
C code
// Unsorted values to search1int arr[] = {3, 7, 2, 9, 5};// Take the first element as the current maximum2int max = arr[0];// Start at index 1, since index 0 is already in max3for (int i = 1; i < 5; i++) { // Replace max when a larger value appears (7, then 9)4 if (arr[i] > max) max = arr[i];5}// Print the largest value: 96printf("%d", max);Output
9
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 6,× 5[× 4]× 4=× 4(× 3)× 3"× 2{× 2}× 2