首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#分别使用for,while,do-while循环方法求的n

2012-09-24 
C#分别使用for,while,do-while循环方法求的n!/* (程序头部注释开始) /pp* 程序的版权和版本声明部分 *

C#分别使用for,while,do-while循环方法求的n!

/* (程序头部注释开始) </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);        }    }}


C#分别使用for,while,do-while循环方法求的n

 

热点排行