Skip to content

Commit 5de2c0b

Browse files
committed
Add RandomChoose.c
1 parent ad57005 commit 5de2c0b

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎c/RandomChoose/RandomChoose.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <time.h>
4+
int main()
5+
{
6+
int input1, input2;
7+
int i;
8+
printf("Please input the number of student:\n");
9+
scanf("%d", &input1);
10+
printf("choose n person in the students randomly\nplease input n:\n");
11+
scanf("%d", &input2);
12+
13+
srand((unsigned int)time(NULL));
14+
int array[input2];
15+
int j;
16+
for (i = 0; i < input2; i++)
17+
{
18+
array[i] = rand() % input1 + 1;
19+
for (j = 0; j < i; j++)
20+
{
21+
if (array[i] == array[j])
22+
{
23+
i--;
24+
}
25+
}
26+
}
27+
i--;
28+
do
29+
{
30+
printf("array[%d]=%d\n", i, array[i]);
31+
i--;
32+
} while (i + 1);
33+
}

‎c/String/slice.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
typedef struct _slice
2+
{
3+
char **element;
4+
int len;
5+
6+
} slice;
7+
slice initializeSlice(slice *Slice);

0 commit comments

Comments
 (0)