- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define MAX 100
- int main(void)
- {
- int i, j, flag, num, a[MAX] = { 0 }, max, ch;
- srand((unsigned)time(NULL));
- printf("Please input max number<1-39>(q to quit): ");
- a:while ((scanf("%d", &max)) == 1)
- {
- if (max >= 40)
- {
- printf("Please input max number<1-39>(q to quit): ");
- while (getchar() != '\\n')
- continue;
- continue;
- }
- for (i = 0; i < max; ++i)
- {
- do{num = rand() % 41 + 1;
- }while(num==8||num==36);
- flag = 1;
- for (j = 0; j < i; ++j)
- {
- if (num == a[j] || num == 8 || num == 36)
- {
- flag = 0;
- break;
- }
- }
- if (flag)
- a[i] = num;
- else
- --i;
- }
- while
- (getchar() != '\\n') continue;
- for (i = 0; i < max; ++i)
- printf("%d ", a[i]);
- printf("\\n");
- printf("Please input max number<1-39>(q to quit): ");
- }
- if (getchar() != 'q')
- {
- puts("q to quit,please!");
- printf("Please input max number<1-39>(q to quit): ");
- while (getchar() != '\\n')
- continue;
- goto a;
- }
- printf("Bye!");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0708201410163.html
来源: http://www.codesnippet.cn/detail/0708201410163.html