Tuesday, March 18, 2014

For Loop Ex 3_(Wk_6) Feb 10-14

Exercise 3: Add all values between 50 and 100 except those values that are divisible by 3.

        static void Main(string[] args)
        {
            int sum = 0;
            for (int counter = 50; counter <= 100; counter++)
            {
                if (counter % 3 == 0)
                {
                    counter++;
                }
                sum += counter;
                Console.WriteLine("Counter: {0} Sum: {1}", counter, sum);
            }
                Console.ReadLine();
        }

No comments:

Post a Comment