如何产生一个随机数,要求这个随机数在1~10或者20~30之间
rand()%10+1
rand()%11+20
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int a = 0;
int b = 0;
srand((unsigned)time(NULL));
a = rand() % 10 + 1;
b = rand() % 11 + 20;
printf("%d\n", a);
printf("%d\n", b);
return 0;
}