c 语言 两个编程小题目 望解答!Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 00:10:54
c 语言 两个编程小题目 望解答!Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated.
c 语言 两个编程小题目 望解答!
Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12.
Figure: 36 Combinations of 2 dice
There are 36 possible combinations of the two dice. Your program should roll the two dice 36,000 times. Use a one-dimensional array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals are reasonable (i.e., there are six ways to roll a 7, so approximately one-sixth of all the rolls should be 7).
请大神们解答!
c 语言 两个编程小题目 望解答!Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated.
我来说一下题目的意思吧:
投掷色子 36000次
每次投掷2个,并计算两个色子的点数和
最后会发现点数和为7的次数最多
思路
写一个投掷两个色子的程序
写一个6*6的色子结果数组,对应两个色子出现的情况,
如1,1 对应 a[0][0]
如4,6 对应 a[3][5]
3. 按副斜对角线方向计算点数和
示例
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
..