📄 lottery155.c
字号:
#include <stdio.h>
#include <time.h>
#define MAX_SIZE 15
#define NUM_IN_ONEGROUP 5
int lotnumber[MAX_SIZE];
void lotteryget(void);
void swap(int i, int j );
main()
{
int i;
int ak;
time_t bx;
struct tm by, *p;
p = &by;
bx = time(NULL);
p = localtime(&bx);
ak = (p->tm_sec);
srand(ak);
for(i = 0; i < MAX_SIZE;i++){
lotnumber[i] = 1+i;
}
for(;;){
getch();
lotteryget();
}
}
void lotteryget()
{
int i = 0 ;int j = 0;
int count = -1;int choose = 0;
int count1 = NUM_IN_ONEGROUP;
int bottem = MAX_SIZE - 1;
int newtotal = MAX_SIZE;
int group = MAX_SIZE / NUM_IN_ONEGROUP;
printf("\n Wellcome and may you lucky!! \n");
printf("The lottery number I picked is : \n");
for(i = MAX_SIZE; i > 0 & count < group; i --){
choose = rand() % newtotal;
swap(bottem,choose);
if(j % NUM_IN_ONEGROUP == 0){
count++;
printf("\n The next lucky number is : \n");
}
printf(" %d " , lotnumber[bottem]);
bottem--;
newtotal--;
j++;
}
if(i>0){
bottem=MAX_SIZE - 1;
newtotal = MAX_SIZE;
for(;i > 0; i--){
swap(bottem,i );
printf(" %d " , lotnumber[bottem]);
bottem--;
count1--;
}
for(j=0;j < count1;j++){
choose = rand() % newtotal;
swap(bottem,choose);
printf(" %d " , lotnumber[bottem]);
}
}
}
void swap(int i,int j){
int temp = lotnumber[i];
lotnumber[i] = lotnumber[j];
lotnumber[j] = temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -