当前位置:网站首页>Call the random function to generate 20 different integers and put them in the index group of institute a

Call the random function to generate 20 different integers and put them in the index group of institute a

2022-06-26 16:44:00 Muzi..

#include<stdio.h>
#include<stdlib.h>
#define N 20
void fun(int *a);
int main()
{
    
	 int x[N],i;
	 fun(x);
	 printf("the result:\n");
	 for(i=0;i<N;i++)
	 {
    
	 	 printf("%4d",x[i]);
	 	 if((i+1)%5==0)
	 	 printf("\n");
	 }
}
void fun(int *a) 
{
       
     int x,i,n=0;
	 x=rand()%20;
	 while(n<20)
	 {
    
	 	 for(i=0;i<n;i++)
	 	 if(x==a[i])
	 	 {
    
	 	 	 break;
		  }
		  if(i==n)
		  {
    
		  	 a[n]=x;n++;
		  }
		  x=rand()%20;
	 }
}
原网站

版权声明
本文为[Muzi..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170506478111.html