实现目标:用户输入想要计算的阶乘数字,反馈输出阶乘计算结果。
相关要点:while循环语句。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace n_
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("阶乘的计算:\n请输入想要计算的阶乘:");
int i=int.Parse(Console.ReadLine());
int j = 1;
int factorial = 1;
while (j<=i) {
factorial = factorial * j;
j++;
}
Console.WriteLine("{0}!={1}",i,factorial);
Console.ReadKey();
}
}
}