转载请注明出处:http://blog.csdn.net/droyon/article/details/9840393
1、数组测试:打印随机数(种子固定,无论执行多少次,输出结果都一样)
#include<stdio.h>
#include<stdlib.h>
#define N 30
void gen_random(int);
void print_random();
int array[N];
int main(void){
gen_random(20);
print_random();
return 0;
}
void gen_random(int upper_bound){
int i;
for(i=0;i<N;i++){
array[i]= rand()%upper_bound;
}
}
void print_random(){
int i;
for(i=0;i<N;i++){
printf("%d \t",array[i]);
if((i+1)%5 == 0){
printf("\n");
}
}
}
打印:
3 6 17 15 13
15 6 12 9 1
2 7 10 19 3
6 0 6 12 16
11 8 7 9 2
10 2 3 7 15