黑马程序员之C#编程基础学习笔记:用while计算1到100之间整数的和;

--------------------------------------------------- 2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------


using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test9
{
      calss Program
      {
            static void Main(string[] args)
            {
                    //用while计算1到100之间整数的和
                    int i= 0;
                    int sum = 0;
                    while( i < =100 )
                    {
                           sum = sum +i ;//每次循环一次sum的值在递增
                           i++;
                    }
                    Console.WriteLine("{0}",sum);//输出1到100之间整数的和为5050
                    Console.ReadKey();
            }
      }

}


--------------------------------------------------- 2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------

你可能感兴趣的:(黑马程序员C#学习笔记)