fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main() {
  6. // 現在の時間をシードとして乱数を初期化
  7. srand(time(NULL));
  8.  
  9. // サイコロ3つの結果を保持する配列
  10. int dice[3];
  11.  
  12. // サイコロの結果を生成
  13. for (int i = 0; i < 3; i++) {
  14. dice[i] = (rand() % 6) + 1; // 1から6の範囲の数値を生成
  15. }
  16.  
  17. // 結果を表示
  18. printf("結果: %d, %d, %d", dice[0], dice[1], dice[2]);
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
結果: 3, 2, 4