首页 > 代码库 > 编程算法 - n个骰子的点数(非递归) 代码(C)

编程算法 - n个骰子的点数(非递归) 代码(C)

n个骰子的点数(非递归) 代码(C)


本文地址: http://blog.csdn.net/caroline_wendy


题目: 把n个骰子仍在地上, 所有骰子朝上一面的点数之和为s. 输入n, 打印出s的所有可能的值出现的概率.


每次骰子的循环过程中, 本次等于上一次n-1, n-2, n-3, n-4, n-5, n-6的次数的总和.


代码:

/*
 * main.cpp
 *
 *  Created on: 2014.7.12
 *      Author: spike
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


using namespace std;


void PrintProbability(int number) {
	const int g_maxValue = http://www.mamicode.com/6;>
输出:

2: 2.777778e-002
3: 5.555556e-002
4: 8.333333e-002
5: 1.111111e-001
6: 1.388889e-001
7: 1.666667e-001
8: 1.388889e-001
9: 1.111111e-001
10: 8.333333e-002
11: 5.555556e-002
12: 2.777778e-002