You are invited to Log in or Register a free Frihost Account!

# Arrays in C

ChrisCh
Hey everyone I'm trying to learn to write a program that prints the highest number on an array list. Here's what I've done so far:
 Code: #include #include  int maxNumbers(int[], int); main() {     /* Load an integer array with values */    int numbers[20] = {10, 34, 23, 54, 23, 12, 56, 76, 34, 21, 25, 46, 67, 69, 53, 28, 84, 90, 92, 12};    printf("The maximum number in the list is %d.\n", maxNumbers(numbers, 20));    /* Pause to see output */    system("pause"); } //THIS IS WHERE I'M HAVING PROBLEMS:  int maxNumbers(int list[], int count) {    int max = 0, x;    for(

Does anyone know how to do this? I'm strugling with this - we have to know the basics like this in order to do an assignment later in the term! If anyone knows anything, I would greatly appreciate your help
Liu
 Code: int maxNumbers(int list[], int count) {   int max=0;   int x;   for (x=0; x max)        max = list[x];   }   return max; }
Traveller
Liu wrote:
 Code: int maxNumbers(int list[], int count) {   int max=0;   int x;   for (x=0; x max)        max = numbers[x];   }   return max; }

Inconsistent variable usage. Should be:

max = list[x];
Liu
Oops, forgot to correct that, thank you.
ChrisCh
thanks guys, that helped a lot
deepak
Travler has given you a decent solution but if you can work with C++ then you could use STL.

 Code: #include #include using namespace std; int main() {      vector a = {1, 3, 4, 5, 6, 7, 11, 1, 3}      return *max_element(a.begin(), a.end()); }