current position：Home>Write a function to randomly generate an array of length n with elements from 0 to 99
Write a function to randomly generate an array of length n with elements from 0 to 99
20220202 19:17:32 【CSDN Q & A】
This is the requirement of the topic , I'm doing the first function , The title says n It's array length , But I don't know how to use that n. I use n=sizeof（a）/sizeof（a[0]) Will report a mistake .
Then I just don't care n, Defined #define N 10, Then call this function two times. , The two arrays generated are the same , Why is that
Refer to the answer 1：
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <windows.h>void Sort(int *p,int n){ int min,i,j,t; for(i=0;i<n1;i++) { min=i; for(j=i+1;j<n;j++) if(p[min]>p[j]) min=j; t=p[i];p[i]=p[min];p[min]=t; }}void Print(int *p,int n){ int j=0; while(j<n) { printf("%d ",p[j]); j++; } printf("\n");}void Init(int a[],int n){ int j; srand((unsigned)time(NULL)); for( j = 0; j < n; j++) { a[j] = rand()%99; }}int main(){ int j=0; int n; printf(" Please enter n："); scanf("%d",&n); int a[n]; Init(a,n); printf(" Original array a[]：");Print(a,n); Sort(a,n); printf(" After ordering a[]:");Print(a,n); Sleep(1000); int b[n]; Init(b,n); printf(" Original array b[]：");Print(b,n); Sort(b,n); printf(" After ordering b[]:");Print(b,n); int n2=n*2; int c[n2]; while(j<n) { c[j]=a[j]; j++; } while(j<n2) { c[j]=b[jn]; j++; } printf(" Original array c[]：");Print(c,n2); Sort(c,n2); printf(" After ordering c[]：");Print(c,n2); return 0; }
Refer to the answer 2：
Refer to the answer 3：
#include <stdio.h>#include <time.h>#include <stdlib.h>void Init(int a[],int n){ int c; for (int i=0;i<n;i++) { c=rand()%100; a[i]= c; }}void Print(int *p,int n){ for (int i=0;i<n;i++) { printf(" %2d", p[i]); } printf("\n");}int main(){ srand((unsigned int)time(NULL)); int b[3]; Init(b,3); printf("b:");Print(b,3); int a[5]; Init(a,5); printf("a:");Print(a,5); return 0;}//b: 2 2 84//a: 23 79 52 60 68//
Refer to the answer 4：
Refer to the answer 5：
#include <stdio.h>#include <stdlib.h>#include <time.h>#define N 10void Init(int a[], int n);int a[N];int main(void){ int i; Init(a, N); for(i = 0; i < N; i++) printf("%d ", a[i]); return 0;}void Init(int a[], int n){ time_t t; /* Initialize the random number generator */ srand((unsigned)time(&t)); while(n >= 0) a[n] = rand() % 100;}
Refer to the answer 6：
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021917263792.html
The sidebar is recommended
 A small problem about string []
 Python fastobjectlistview cannot operate on setitem * *
 What should I fill in at the crosswalk
 College C language programming c + + Programming
 Appium + Python + Android JDK failed to connect to the mobile phone to run app
 I think the activity can be started in the background above Android Q. how to realize it
 Use the predict type parameter to define a method for filtering books
 Problems related to the use of C PropertyGrid
 How to set the gain & lt^ u
 Click one H5 item in the app to jump to another H5 item
guess what you like

Find a solution to the error of this r code

Python will test Put the PY file in a python package (such as D: \ TT), import the package test in test2, and output the value of the variable data.

When using PPO strategy to train reinforcement learning model, how to evaluate the quality of the model and judge whether it converges?

Calculate the number of uppercase letters, lowercase letters and numbers in any string

If you work from home, the same operation will fail

Content encapsulation under threelevel classification of Java

The idea switches branches and the project directory structure disappears

1. Customize a  function to realize the following functions: input the accuracy e, and use the following formula to calculate the approximate value of cosx until the absolute value of the last  item is less than E. It is required to define and call the

Find its Huffman code? Give the coding process and coding results (please give the large probability as 1 and the small probability as 0) Calculate the average code length. Calculate the compression ratio before and after coding

C language and documents to solve students' performance problems
Random recommended
 C language file encryption applet problem
 Three types of MPEG images
 How to write this program code
 Questions about data structure: data structure sequence table (languagec language)
 A problem of energy economics
 Vscode why does Python have two problems when the external window is running? Press any key to continue?
 Using 7474n to build JK Trigger and D trigger.
 C language twodimensional array, for interpretation
 When simulating with botu and factory IO, factory IO I2 The contacts behind 0 are not working
 How to solve termux qqbot error?
 C + + getline cannot correctly read the console input Chinese
 Android development bookkeeping
 About the problem of C language: input 12 + 3 with DEVC + + to get 12.000000. I don't know what's wrong, include & lt; stdio. h＆gt;
 Prompt the user to enter an integer n and N real numbers, calculate and output the sum of the negative numbers in the input n real numbers.
 Using C52 and LCD1602 to simulate an electronic clock, how to program four modes and one LED flashing for four keys
 Do any friends know how to do this? Please
 For problems occurred during GCN reproduction, it is suggested that the openposedemo file cannot be found
 TypeError: string indices must be integers
 I really can't find answers to the exercises after freshman class.
 How is the MSE value compared with the vector?
 How to set a draw when making tic tac toe chess in Python
 Solving Python language C language
 How does Maple set a variable to be any integer from a certain interval
 How to realize that the opening of a website computer is one interface and the opening of a mobile phone is another interface, similar to self adaptation?
 After entering two indefinite length arrays and sorting them, merge and sort the two arrays again
 The computer has a web, but it can't access other web pages except the navigation page display
 C + + how to do this program
 Want to know how to find the parameters of this function? How should the matlab code knock
 Multi module project cannot inject mapper java
 MapReduce average score how to find the average of each line
 Wechat applet rendering layer error
 What does this mean? Why can't I open my QQ
 CMD run Py file encountered a problem
 Help me see what's wrong
 Why not 13bingo
 Decipher the password and there is no result after running?
 Ask you why this code can't run (◞‸◟)
 Hello, can you extract the of our applet
 Why not show folders when attaching a database
 How can the last line end with 0 without spaces