Zu Sung Park

Zu Sung Park

  • NA
  • 5
  • 2.7k

Stuck on a simple problem: Find the sum of all the multiples of 3 or 5 below 1000.

Dec 7 2011 7:16 AM
Hi need some help with the summing of this simple problem. Seems that it doesn't save on the arrays.
Here is the code:

using System;


namespace test
{
    class Program
    {
        static void Main()
        {
            Program p = new Program();
            p.sum(1000);


            Console.ReadLine();
        }


        public void sum (int tal)
        {
            for (int i = 1; i < tal; i++)
            {
                int[] array= new int[1000];
                if (i % 3 == 0 || i % 5 == 0)
                {
                    array[i] += i;
                    Console.WriteLine(array[i]);
                }
            }
        }
    }
}

Can someone give me the guidance to complete this one!?

Best regards,



Answers (5)