日期:2014-05-17 浏览次数:21350 次
/* (程序头部注释开始) </p><p>* 程序的版权和版本声明部分 
* Copyright (c) 2011, 烟台大学计算机学院学生                              
* 作    者:   李兆庆                         
* 完成日期:   2012      年   9    月    9   日 
* 输入描述:   do-while循环方法   
* 问题描述及输出:  编写一个C#程序,分别使用for,while,do-while循环语句计算n!.
* 程序头部的注释结束 
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace No._2
{
    class Program
    {
        static void Main(string[] args)
        {
            int fac = 1;
            int i = 1;
            Console.Write("输入一个数字:");
            string strInput = Console.ReadLine();
            Console.WriteLine("输入的内容是:{0}", strInput);
            int n = short.Parse(strInput);
            do
            {
                fac = fac * i;
                ++i;
            } while (i <= n);
            Console.WriteLine("n的阶乘为:{0}", fac);
            Console.ReadKey(false);
        }
    }
}
/* (程序头部注释开始) </p><p>* 程序的版权和版本声明部分 
* Copyright (c) 2011, 烟台大学计算机学院学生                              
* 作    者:   李兆庆                         
* 完成日期:   2012      年   9    月    9   日 
* 输入描述:    while循环方法 
* 问题描述及输出:  编写一个C#程序,分别使用for,while,do-while循环语句计算n!.
* 程序头部的注释结束 
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace No._2
{
    class Program
    {
        static void Main(string[] args)
        {
            int fac = 1;
            int i = 1;
            Console.Write("输入一个数字:");
            string strInput = Console.ReadLine();
            Console.WriteLine("输入的内容是:{0}", strInput);
            int n = short.Parse(strInput);
            while (i <= n)
            {
                fac = fac * i;
                ++i;
            }
            Console.WriteLine("n的阶乘为:{0}", fac);
            Console.ReadKey(false);
        }
    }
}
/* (程序头部注释开始) </p><p>* 程序的版权和版本声明部分 
* Copyright (c) 2011, 烟台大学计算机学院学生                              
* 作    者:   李兆庆                         
* 完成日期:   2012      年   9    月    9   日 
* 输入描述:  for 循环方法  
* 问题描述及输出:  编写一个C#程序,分别使用for,while,do-while循环语句计算n!.
* 程序头部的注释结束 
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace No._2
{
    class Program
    {
        static void Main(string[] args)
        {
            int fac = 1;
            Console.Write("输入一个数字:");
            string strInput = Console.ReadLine();
            Console.WriteLine("输入的内容是:{0}", strInput);
            int n = short.Parse(strInput);
            for (int i = 1; i <= n; i++)
            {
                fac = fac * i;
            }
            Console.WriteLine("n的阶乘为:{0}", fac);
            Console.ReadKey(false);
        }
    }
}
