Tuesday, March 18, 2014

Do_While_Loop_Ex_2 (Wk-7) Feb 17-21, 2014

Exercise 2: Add all values between 1000 and 2000, that are divisible by 7.

        static void Main(string[] args)
        {
            int N = 1000;
            int sum = 0;
            do
            {
                if (N % 7 == 0)
                {
                    sum += N;
                    Console.WriteLine("Number: {0} Sum: {1}", N, sum);
                }
                    N++; //get next value

            } while (N <= 2000);
           
            Console.ReadLine();
        }

No comments:

Post a Comment