zoukankan      html  css  js  c++  java
  • 例题:三个红球,五个白球,八个黑球,随机组成八个球,八个球里至少有一个白球,问有几种可能性。主要学习for循环穷举,锻炼计算机思维

       int n = 0; //定义初始值为0
                for (int a = 0; a<=3; a++)
                {
                    for (int b = 0; b <= 5; b++)
                    {
                        for (int c = 1; c <= 8; c++)
                        {
                            if (b>=1&&a+b+c==8)  //输入条件,至少一个白球,三种球加起来个数为8个
                            {
                                Console.WriteLine(a+"红球"+b+"白球"+c+"黑球");
                                n++; //每有一种可能性加一次
                            }
                        }
                    }
                }
                Console.WriteLine("共有"+n+"种可能性");
                Console.ReadLine();

  • 相关阅读:
    poj1330 Nearest Common Ancestors
    poj3237 Tree
    spoj2798 QTREE3 Query on a tree again!
    spoj913 QTREE2 Query on a treeⅡ
    自动类型转换
    js "+"连接符号
    js parseFloat
    js字符串与数字的运算
    js prompt
    js数组排序
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4428436.html
Copyright © 2011-2022 走看看