Find the largest number in an array - C Array

C examples for Array:Array Value

Description

Find the largest number in an array

Demo Code

#include <stdio.h>
int main()/* w  ww.  ja  va 2 s  .com*/
{
    int myArray[10] = {12, 5, 21, 15, 32, 10, 6, 31, 11, 10};
    int bestGame = 0; //The comparison variable for best scoring game
    int gmMark = 0;   // This will mark which game is the best scoring game

    for (int i=0; i<10; i++){
        if (myArray[i] > bestGame){
            bestGame = myArray[i];
            gmMark = i;
        }
    }
    printf("The best game was game #%d\n", gmMark+1);
    printf("Scored %d points\n", myArray[gmMark]);

    return(0);
}

Result


Related Tutorials