主页
C 语言
C 随机数
demo_random_number_die
运行 ❯
×
更改方向
保存代码
更改主题
#include
#include
#include
int main() { srand(time(NULL)); int dice1 = (rand() % 6) + 1; int dice2 = (rand() % 6) + 1; printf("You rolled %d and %d (total = %d)\n", dice1, dice2, dice1 + dice2); return 0; }
You rolled 4 and 2 (total = 6)