Monday, March 17, 2014

Loop Structures (While)_Ex_2_Wk (5)_Feb 3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IterationLoopStructure
{
    class Program
    {
        static void Main(string[] args)
        {
            //Write a while loop that adds all the consecutive integers
            //between 200 and 300


            int counter = 200;
            int sum = 0;
            while (counter <= 300)
            {
                sum += counter;
                Console.WriteLine("Counter: {0} Sum: {1}", counter, sum);
                counter++;
            }
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment