循环初练 for

  class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int a, b; int s = 0;
                Console.WriteLine("请输入第一个数:");
                a = Convert.ToInt32(Console.ReadLine());  //最简单的循环数,从a到b的和
                Console.WriteLine("请输入第二个数:");
                b = Convert.ToInt32(Console.ReadLine());
                for (int i = a; i <= b; i++)   //从a一直加到b
                {
                    s = s + i;
                }
                Console.WriteLine("那么从"+a+"到"+b+"的和为"+s);

 

                Console.ReadLine();

posted @ 2015-03-31 18:58  XCml  阅读(133)  评论(0编辑  收藏  举报