fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main(void) {
  6. // your code goes here
  7.  
  8. int graph[8][8] = //サイズ8の有向グラフの形
  9. {
  10. {0,0,0,0,0,0,0,0},
  11. {0,0,0,0,0,0,0,0},
  12. {0,0,0,0,0,0,0,0},
  13. {0,0,0,0,0,0,0,0},
  14. {0,0,0,0,0,0,0,0},
  15. {0,0,0,0,0,0,0,0},
  16. {0,0,0,0,0,0,0,0},
  17. {0,0,0,0,0,0,0,0}
  18. };
  19.  
  20. int r=1;
  21. int a,b;
  22. while(r<9){ //ランダムで8個の頂点を生成
  23. a = rand() % 8;
  24. b = rand() % 8;
  25. if (graph[a][b] >0);
  26. else{
  27. graph[a][b] = r;
  28. r++;
  29. }
  30. }
  31.  
  32. for(int i = 0; i < 8; i++){ //生成した有向グラフを表示
  33. for(int g = 0; g < 8; g++){
  34. printf("%d",graph[i][g]);
  35. }
  36. printf("\n");
  37. }
  38.  
  39.  
  40.  
  41. return 0;
  42. }
  43.  
  44.  
  45.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
00000000
00020503
00064000
00000070
00800000
00000000
00000000
00000010