zoukankan      html  css  js  c++  java
  • 练习:C#---for循环(整数和、阶乘、楼梯)

    // 输入正整数n,求1-n的和
                Console.Write("请输入一个正整数:");
                int n = int.Parse(Console.ReadLine());
                int sum = 0;
                for (int a = 1; a <= n;a++ )
                {
                    sum = sum + a; 
                }
                Console.WriteLine("1-"+n+"的正整数和为:"+sum);
                Console.ReadLine();

    // 求1-n的阶乘
                Console.Write("请输入一个正整数:");
                int m = int.Parse(Console.ReadLine());
                long jiecheng = 1;
                for (int a = 1; a <= m; a++)
                {
                    jiecheng = jiecheng * a;
                }
                Console.WriteLine(m + "的阶乘为:" + jiecheng);
                Console.ReadLine();  

    // 100节楼梯,0-49节分数等于节数,50以后每节10分,输入节数得出分数。
                Console.Write("请输入楼梯数:");
                int s = int.Parse(Console.ReadLine());
                int score = 0;
                if (s > 100 || s < 0)
                {
                    Console.WriteLine("您的输入有误");
                }
                else 
                {
                    for (int a = 1; a <= s;a++ ) 
                    {
                        if (a < 50)
                        {
                            score = score + a;
                         }
                        else
                        {
                            score = score + 10;
                         }
                    }
                }
                Console.WriteLine("您的分数是:"+score);
                Console.ReadLine();

  • 相关阅读:
    create joint
    delphi 使用parent让进度条上显示文字
    abSymMeshMEL.txt
    ini写配置信息
    CreateBindGroupNode.txt
    CreateaJointCurve.txt
    09 IKFKMatch.txt
    TIF_to_MAP.BAT
    ImportBVHv20.txt
    FormatDateTime 一段以时间为命令的代码
  • 原文地址:https://www.cnblogs.com/xiao55/p/5467255.html
Copyright © 2011-2022 走看看