How do I store the value of the max integer in an array before repeating loop?

43 Views Asked by At

It's been a couple hours. I don't understand arrays well enough to determine the right way to save a value as max and then determine the maximum value within the array. Please help explain how to make the for loop correctly. Thanks.

#include <stdio.h>
#include <conio.h>
#define SIZE 3

    int main (void){
        int max;
        int min;
        int myArray[SIZE];
        int count;
        printf("Please enter integers\n");
        for (count=0;count<=SIZE;count++){
        scanf("%d",&myArray[count]);
    }
        for (count=0;count<=SIZE;count++){
        printf("The values of myArray are %d\n",myArray[count]);
    }
        for (count=0;count<=SIZE;count++){
         max=myArray[0];
         if (myArray[count]>max){
                                 myArray[count]=max;
                                 }
                                 }

        printf("The largest is %d\n",max);
        printf ("The smallest is %d\n",min);
    getch();

    return 0;
    }
1

There are 1 best solutions below

1
On BEST ANSWER
    max=0;
    for (count=0;count<SIZE;count++){
        if (myArray[count]>max){
                             max = myArray[count];
                             }
        }

You need change all <= SIZE to < SIZE