current position:Home>Questions about C: please be more detailed about C programming program

Questions about C: please be more detailed about C programming program

2022-02-04 16:34:31 CSDN Q & A

img

C# Programming questions, please be more detailed , beginner , thank you




Take the answer :
using System;namespace ConsoleApp1{    class Program    {       static long fac(int n)// Calculation n The factorial  {            return n == 0 ? n * fac(n - 1) : 1;// Such as n by 0 or 1 The return value is 1, If not 0,1 Then return to n*(n-1)!        }        static void Main(string[] args) {            Console.WriteLine(" Input n Value :");            int n = int.Parse(Console.ReadLine());            long e = 0;            for (int i = 0; i <= n; i++)            {                e = e + 1 / fac(n);//  Calculated value e = 1/0!+1/1!+1/2!+......+1/n!            }            Console.WriteLine("e Value :"+e.ToString());        }    }}


Other answers 2:

First use a function to calculate the factorial .
Then find its reciprocal .
Sum up .


Other answers 3:

You can use the idea of recursion to calculate

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041634296824.html

Random recommended