Reputation: 115
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;
}
Upvotes: 0
Views: 30
Reputation: 2583
max=0;
for (count=0;count<SIZE;count++){
if (myArray[count]>max){
max = myArray[count];
}
}
You need change all <= SIZE to < SIZE
Upvotes: 1