如何在重复循环之前将最大整数的值存储在数组中?
How do I store the value of the max integer in an array before repeating loop?
已经几个小时了。我不太了解数组,无法确定将值保存为最大值然后确定数组中最大值的正确方法。请帮助解释如何正确地使 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;
}
max=0;
for (count=0;count<SIZE;count++){
if (myArray[count]>max){
max = myArray[count];
}
}
您需要将所有 <= SIZE 更改为 < SIZE
已经几个小时了。我不太了解数组,无法确定将值保存为最大值然后确定数组中最大值的正确方法。请帮助解释如何正确地使 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;
}
max=0;
for (count=0;count<SIZE;count++){
if (myArray[count]>max){
max = myArray[count];
}
}
您需要将所有 <= SIZE 更改为 < SIZE