Archived
1
0
This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SomeLab/cs3/C_Sharp_3_1/Program.cs
2025-10-24 17:19:46 +08:00

37 lines
970 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
namespace C_Sharp_3_1
{
public class Program
{
static void Main()
{
int n = -1, result = 1, i = 1;
Console.WriteLine("请输入一个正整数n");
while (n < 0)
{
n = int.Parse(Console.ReadLine());
}
// For循环实现阶乘
for (i = 1; i <= n; i++)
{
result *= i;
}
Console.WriteLine("for 循环 {0}={1}", n, result);
// while循环实现阶乘
while (n > 1)
{
result *= n;
n--;
}
Console.WriteLine("while 循环 {0}={1}", n, result);
//do...while循环实现阶乘
do
{
result *= i;
i ++;
} while (i<=n);
Console.WriteLine("do...while 循环 {0}={1}", n, result);
}
}
}