c 语言 两个编程小题目 望解答!
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/08 01:36:36
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).
请大神们解答!
思路写一个投掷两个色子的程序写一个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 ..
再问: 那你能写出这个程序吗?
再答: 说真的,程序不是很难,但是我只想说明思路。楼主自己编写比较好哦,编程学习重要的是自己编写(那样子技术提升才快,还会有成就感,要是写程序时遇到问题,再问人也不迟)。