15.6k views
1 vote
Given integer variables seedVal and sidesNum, output two random dice rolls. The die is numbered from 1 to sidesNum. End each output with a newline.

Ex: If sidesNum is 12, then one possible output is:

5
12

1 Answer

3 votes

Answer:

#include <stdio.h>

#include <stdlib.h>

int main() {

int seedVal;

int sidesNum;

scanf("%d%d", &seedVal, &sidesNum);

srand(seedVal);

int dice1 = (rand() % sidesNum) + 1;

int dice2 = (rand() % sidesNum) + 1;

printf("%d\\%d\\", dice1, dice2);

return 0;

}

User Dustinevan
by
7.6k points