You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
791 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<bits/stdc++.h>
using namespace std;
/*
用随机函数产生100个[099]范围内的随机整数,
统计个位上的数字分别为0123456789的数的个数并打印出来
*/
#define MAX 101
void input(int num[]) {
int i;
srand((unsigned)time(NULL));
for(i=1; i<MAX; i++)
num[i]=rand()%100;
}
void output(int num[]) {
int i;
for(i=1; i<MAX; i++) {
printf("%5d", num[i]);
if(0==i%10)
printf("\n");
}
printf("\n");
}
void cal_num(int num[], int count[]) {
int i, mod;
for(i=1; i<MAX; i++) {
mod=num[i]%10;
count[mod]++;
}
}
int main() {
int num[MAX];
int i, count[10];
memset(count, 0, 10*sizeof(int)); /* initial count[] to 0 */
input(num);
printf("100 num:\n");
output(num);
cal_num(num, count);
for(i=0; i<10; i++)
printf("%d: %d\n", i, count[i]);
return 0;
}