• 函数阶乘累加求和


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 函数阶乘累加和
    {
        class Program
        {
            //没有返回值,没有参数
            public void jiehe()
            {
                Console.Write("请输入一个整数:");
                int a = int.Parse(Console.ReadLine());
                int sum = 0;
                int jie = 1;
                for (int i = 1; i <= a; i++)
                {
                    jie *= i;
                    sum += jie;
                }
                Console.WriteLine(sum);
            }
            //没有返回值,有参数
            public void jiehe(int z)
            {
                int sum = 0;
                int jie = 1;
                for (int i = 1; i <= z; i++)
                {
                    jie *= i;
                    sum += jie;
                }
                Console.WriteLine(sum);
            }
            //有返回值,没有参数
            public int jiehe1()
            {
                Console.Write("请输入一个整数:");
                int a = int.Parse(Console.ReadLine());
                int sum = 0;
                int jie = 1;
                for (int i = 1; i <= a; i++)
                {
                    jie *= i;
                    sum += jie;
                }
                return sum;
            }
            //有返回值,有参数
            public int jiehe2(int z)
            {
                int sum = 0;
                int jie = 1;
                for (int i = 1; i <= z; i++)
                {
                    jie *= i;
                    sum += jie;
                }
                return sum;
            }
            static void Main(string[] args)
            {
    
                //阶乘累加求和
    
                Program hanshu = new Program();
                //没有返回值,没有参数
                //hanshu.jiehe();
                //没有返回值,有参数
                //Console.Write("请输入一个整数:");
                //int a = Convert.ToInt32(Console.ReadLine());
                //hanshu.jiehe(a);
                //有返回值,没有参数
                //int sum = hanshu.jiehe1();
                //Console.WriteLine(sum);
                //有返回值,有参数
                Console.Write("请输入一个整数:");
                int a = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine(hanshu.jiehe2(a));
               
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    (转) 理解Angular中的$apply()以及$digest()
    Gulp 有用的地址
    AngularJS中Directive指令系列
    让博客园博客中的图片支持fancybox浏览
    Drupal7 实现like(点赞)功能
    Drupal7 针对特定条件才显示区块
    Windows server 2008 tomcat间歇性掉线关闭
    关于tomcat8在windows2008下高并发下有关问题的解决方案
    combotree 的简单使用2
    @responseBody 返回更多数据
  • 原文地址:https://www.cnblogs.com/fengsantianya/p/5493666.html
Copyright © 2020-2023  润新知