0

I have the following code which is supposed to find the maximum value in a preset array. However, the result that I print out is 32766. Could anyone assist me with understanding what I did wrong?

#include <stdio.h>

int main() {
    int input[] = { 3, 2, 5, 4, 1 };
    int result;
    int index = 0;
    int tempmax = input[0];

    for (index = 0; index < sizeof input; index++) {
        if (tempmax < input[index])
            result = input[index];
    }

    printf("The largest number in the array is %d\n", result);
    return 0;
}
Mat
  • 202,337
  • 40
  • 393
  • 406
Kane
  • 91
  • 7

0 Answers0