求高手帮做1个C++程序

来源:百度知道 编辑:UC知道 时间:2024/06/11 08:25:36
题目如下:
统计10000个0~9的随机数分布情况
并显示0~9各数的出现次数!

int c[10];
int i;
int t;
for (i = 0 ; i < 10000 ; i++)
{
t = rand()%10;
c[t]++;
}
for (i = 0 ; i < 10 ; i++)
{
printf("%d:%d次",i,c[i]);
}

#include<iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

using namespace std;

int main()
{
int number[10];
for(int i=0;i<10;i++)
number[i]=0;
int n;
srand( (unsigned)time( NULL ) );
for(int i;i<10000;i++)
{
n=rand()%10;
number[n]++;
}
for(int i=0;i<10;i++)
cout<<i<<"出现"<<number[i]<<"次"<<endl;
}

#include <iostream.h>
#include <time.h>
int main()
{
int a[10];
for (int i = 0;i < 10; i++)
a[i] = 0;

int temp;
srand( (unsigned)time( NULL ) );
for(i