다음은 N 주사위 롤러를 에뮬레이트하는 코드입니다. 이것은 1-6 사이의 난수를 생성하여 수행할 수 있습니다.
알고리즘
Begin Declare n Read n For i = 0 to n-1 do Generate sequence with rand() mod 6 + 1 Print the sequence Done End
예시 코드
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
cout << "Enter the number of dice: ";
int n;
cin >> n;
cout << "The values on dice are: ";
for (int i = 0; i < n; i++)
cout << (rand() % 6) + 1<<" ";
} 출력
Enter the number of dice: The values on dice are: 2 5 4 2 6 2 5