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

第二周 任务四 分别使用for,while,do-while循环语句计算 n

2012-09-14 
第二周任务四分别使用for,while,do-while循环语句计算n!/* * 程序头部注释开始* 程序的版权和版本声明部分

第二周 任务四 分别使用for,while,do-while循环语句计算 n!

/* * 程序头部注释开始   * 程序的版权和版本声明部分   * Copyright (c) 2011, 烟台大学计算机学院学生   * All rights reserved.   * 文件名称:编写一个控制台应用--分别使用for,while,do-while循环语句计算  n!                              * 作    者:薛广晨                               * 完成日期:2011  年 09 月  09  日   * 版 本号:x1.0               * 对任务及求解方法的描述部分   * 输入描述:  * 问题描述:编写一个控制台应用--分别使用for,while,do-while循环语句计算  n!  * 程序输出:   * 程序头部的注释结束 */using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace do_While{    class Program    {        static void Main(string[] args)        {            int i = 1;            int s = 1;            Console.Write("请输入一个数:");            int n = int.Parse(Console.ReadLine());            for (i = 1; i <= n; ++i)              {                 s = s * i;              }              Console.WriteLine("用for 循环控制语句求{0}!的值为:{1}", n, s);            i = 1;            s = 1;            while (i <= n)              {                 s = s * i;                 ++i;              }              Console.WriteLine("用while 循环控制语句求{0}!的值为:{1}", n, s);            i = 1;            s = 1;            do            {                s = s * i;                i++;            } while (i <= n);            Console.WriteLine("用do-while 循环控制语句求{0}!的值为:{1}", n, s);            Console.ReadKey(false);        }    }}


第二周  任务四  分别使用for,while,do-while循环语句计算  n第二周  任务四  分别使用for,while,do-while循环语句计算  n

 

热点排行