# include <stdio.h>int main(void){ int len, i; scanf("%d", &len); int a[len]; int max, min, j; for(i=0; i<len; ++i) scanf("%d", a[i]); max = a[0]; min = a[0]; for(i=1; i<len; ++i) { if(max < a[i]) { j = max; max = a[i]; a[i] = j; } if(min > a[i]) { j = min; min = a[i]; a[i] = j; //编译器提示问题在这,但是总想不出为什么?? } } return 0;}
1 回答
江户川秋风
TA贡献78条经验 获得超21个赞
看本代码第12行注释
#include <stdio.h> int main(void) { int len, i; printf("输入数字的个数:"); scanf("%d", &len); int a[len]; int max, min, temp; for(i=0;i<len;i++) { printf("输入第%d个数:",i+1); scanf("%d", &a[i]);//加上取地址运算符& } max = a[0]; min = a[0]; for(i=1; i<len; ++i) { if(max < a[i]) { temp = max; max = a[i]; a[i] = temp; } if(min > a[i]) { temp = min; min = a[i]; a[i] = temp; } } printf("最大数:%d,",max); printf("最小数:%d\n",min); return 0; }
- 1 回答
- 0 关注
- 1397 浏览
添加回答
举报
0/150
提交
取消