【发布时间】:2014-03-21 20:46:42
【问题描述】:
代码用于将整数扫描到数组中,当输入0时循环停止扫描。 在值被扫描后,数组内的最高值和最低值将被找到 找到 high 和 low 后,打印数组索引 high 和 low 之间的值
所以如果输入 5,2,8,7,6,12,6,4,5 输出应该是 2,7,6,12
我的程序在扫描输入值并输入 0 以结束循环后失败
#include <stdio.h>
int main(){
int high=4;
int low,i;
int array[25];
int count=0;
printf("Please input numbers for array:");
for(i=0;array[i]!=0;i+=1){
scanf("%d",&array[i]);
count+=1;
}
for(i=0;i<count;i+=1){
if(array[i]>array[high]){
high=i;
}
}
low=high;
for(i=0;i<count;i+=1){
if(array[i]<array[low]){
low=i;
}
}
for(i=low;low<=high;i+=1){
printf("%d,",array[i]);
}
}
【问题讨论】:
-
我的水晶球告诉我:
i=count不是你想要的 for 循环条件表达式。 -
缓冲区溢出 t 减 26...
-
是的,谢谢你的小疏忽