已经过了几个小时。我不太了解数组,以确定将值保存为max的正确方法,然后确定数组中的最大值。请帮助解释如何正确地进行for循环。感谢。
#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;
}
答案 0 :(得分:1)
max=0;
for (count=0;count<SIZE;count++){
if (myArray[count]>max){
max = myArray[count];
}
}
您需要将所有&lt; = SIZE更改为&lt; SIZE