分析如下程序的逻辑错误,该程序要实现的功能是:找到一维数组test中的最小值和test[0]交换,找到一维数组test中的最大值和test[9]交换,最后输出交换后的结果。
#include
int main() {
int test[]={15,5,1,6,0,8,12,7,2,9};
int temp,i,j;
int max=0,min=0;
int n=sizeof(test)/sizeof(test[0]);
for(i=1;i
if(test[i]>test[max]) max=i;
if(test[i]
}
temp=test[0];
test[0]=test[min];
test[min]=temp;
temp=test[n-1];
test[n-1]=test[max];
test[max]=temp;
for(j=0;j
printf("%d\t",test[j]);
}
}