作业帮 > 综合 > 作业

编写程序,实现输入n个整数,输出其中最小的数,并指出其是第几个数

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/29 17:49:43
编写程序,实现输入n个整数,输出其中最小的数,并指出其是第几个数
编写程序,实现输入n个整数,输出其中最小的数,并指出其是第几个数
#include
int main(void){
int count = 0;
int i,temp;
int num[100] ={};
char stat;
while(1){
printf("请输入第%d个整数:\n",count + 1);
scanf("%d",&num[count]);
count++;
printf("是否还要继续输入? y是/n否");
getchar();
scanf("%c",&stat);
if(stat == 'y')
continue;
else if(stat == 'n')
break;
else{
printf("您输入的指令非法!");
return -1;
}
}
temp = num[0];
for(i = 1;i < count;i++){
if(temp < num[i])
temp = num[i];
}
i = 0;
while(1){
i++;
if(temp == num[i])break;
}
printf("您输入的第%d个数最大,值是%d\n",i + 1,temp);
return 0;
}
再问: 这有错额、、、
再答: 哪有错?我都运行过才上传的。。
再问: Compiling... EX5.c C:\Documents and Settings\狐狸、悦.PCOS-05121633\桌面\1317426047孙悦20140218\EX5\EX5.c(6) : error C2059: syntax error : '}' 执行 cl.exe 时出错. EX5.obj - 1 error(s), 0 warning(s)
再答: 你这什么编译器?试试在num数组初始化的大括号里面写一个0
再答: int num[100] ={0}; 试试在这里面写一个0试试,再出错你检查一下你是不是哪里少复制了一个括号,或者分号啥的,陈需运行一点问题没有,已经测试过了的
再问: 亲 谢谢 现在对了 不过能不能改得简单点 我数组等等什么的 还没教呢、、、拜托了!!!!!!
再答: 哥哥您能不能采纳一下。。。。,我那个现编的。。你说的可以实现。。。。 #include int main(void){ int count = 0; int num,n; int temp = 0; char stat; while(1){ printf("请输入第%d个整数:\n",count + 1); scanf("%d",&num); count++; if(temp < num){ temp = num; n = count; } printf("是否还要继续输入? y是/n否"); getchar(); scanf("%c",&stat); if(stat == 'y') continue; else if(stat == 'n') break; else{ printf("您输入的指令非法!"); return -1; } } printf("您输入的第%d个数最大,值是%d\n",n,temp); return 0; }
再答: 新代码已经上传
再问: 我是妹妹 哼哼 知道了啦~~~~~~~
再答: 新代码看到了吧?已经上传上去了,有问题可以给我留言,qq494030896
再答: 给你上传的代码是有漏洞的,比如,第一个数,输入0,n值是不对的,而且输入两个相等的数切该数值为最大值,只能记录第一个数值是第几个,这些都可以优化,建议你自己优化一下试试