c++编程题。从键盘输入10个整数,其值在0至5范围内,用-1作为输入结束的标志,统计每个整数的个数

如题所述

第1个回答  推荐于2016-05-25
#include<iostream>
using namespace std;
#include<stdio.h>
main()
{
int a[6];
int i,v;
for (i=0;i<6;i++) a[i]=0;
printf("input 10 data value 0-5, then enter -1:\n");
while(1){
scanf("%d",&v);
if (v == -1)break;
if (v >= 0 && v<=5) a[v]++;
}
for (i=0;i<6;i++) printf("%d -- %d\n",i,a[i]);
return 0;
}本回答被提问者和网友采纳
第2个回答  2015-05-11
arr[n] += 1,数组全部初始化为0
第3个回答  2015-05-11
switch语句加循环
第4个回答  2015-05-11
循环 加判断加随机数 自己写写啊…追问

while(1)是啥

while(1)是啥

while(1)是啥

追答

//tieba.baidu.com/i/sys/jump?un=%CCK%BA%C9%A1%ACqcmz%A8I" onclick="Stats.sendRequest('fr=tb0_forum&st_mod=pb&st_value=atlink');" onmouseover="showattip(this)" onmouseout="hideattip(this)" username="%CCK%BA%C9%A1%ACqcmz%A8I" target="_blank" class="at">蘇荷‖qcmz↖ :死循环 除非用break跳出

相似回答