效果图: 现在输入这十个数,注意要递增 1 2 2 2 2 3 4 4 5 5 1出现1次 2出现4次 3出现1次 4出现2次 5出现2次 请按任意键继续.................
/*
功能:统计输入整形数中每个数出现的次数-C++数组的简单操作
日期:2013-09-12
*/
#include<iostream>
using namespace std;
int main(void)
{
int arr[10];
int num = 0;
int i,j;
cout << "现在输入这十个数,注意要递增" <<endl;
for (i=0;i<10;i++)
{
cin >> arr[i];
}
for (i=0;i<10;i=j)
{
for (j=i;j<10;j++)
{
if (arr[i]==arr[j])
{
num++;
if (9==j)
{
cout<<arr[i]<<"出现"<<num<<"次"<<endl;
}
}
else
{
cout<<arr[i]<<"出现"<<num<<"次"<<endl;
num = 0;
break;
}
}
}
system("pause");
return 0;
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有