《C Primer Plus》第6版 编程练习 第十二章 第六题

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

int main(void)
{
int i,j;
int one=0;
int two=0;
int three=0;
int four=0;
int five=0;
int six=0;
int seven=0;
int eight=0;
int nine=0;
int ten=0;
int at[100]; //一个种子生成的随机数
int ar[10]; //包含10个种子的数组
puts(“请输入10个正整数作为种子:”);
for(i=0;i<10;i++)
scanf("%d",&ar[i]);
for(i=0;i<10;i++)
{
srand((unsigned int) ar[i]);
for(j=0;j<100;j++)
{
at[j]=rand() % 10 + 1;
if(at[j]==1)
one++;
if(at[j]==2)
two++;
if(at[j]==3)
three++;
if(at[j]==4)
four++;
if(at[j]==5)
five++;
if(at[j]==6)
six++;
if(at[j]==7)
seven++;
if(at[j]==8)
eight++;
if(at[j]==9)
nine++;
if(at[j]==10)
ten++;
}

}

printf("测试结果如下\n");
printf("数字 1:  %d    个。\n",one);
printf("数字 2:  %d    个。\n",two);
printf("数字 3:  %d    个。\n",three);
printf("数字 4:  %d    个。\n",four);
printf("数字 5:  %d    个。\n",five);
printf("数字 6:  %d    个。\n",six);
printf("数字 7:  %d    个。\n",seven);
printf("数字 8:  %d    个。\n",eight);
printf("数字 9:  %d    个。\n",nine);
printf("数字10:  %d    个。\n",ten);

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值