生成多个随机数的数组,srand()函数

更多资料请点击:我的目录

c语言-生成多个随机数的数组,只要调用 srand()此函数就可以实现,具体用法如下:

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

srand(time(NULL));			//生成随机数
	for(k = 0; k < 5; k++)			//遍历5个数组
	{		
		for(i = 0; i < 4; i++)		//每个数组4个随机数
		{
			random_num[k][i]=rand()%9+1;
			for(j = 0; j < i; j++)
			while(random_num[k][i] == random_num[k][j])	//两个数相等时
			{
				random_num[k][i]=rand()%9+1;		//重新赋值
				j=-1;
			}
		}
	}

更多资料请点击:我的目录

发布了75 篇原创文章 · 获赞 35 · 访问量 5917

猜你喜欢

转载自blog.csdn.net/weixin_43793181/article/details/104114563