试图解决Project Euler#1的问题

时间:2013-04-10 04:03:16

标签: c#

我在尝试制作一个小应用来解决Project Euler Problem #1时遇到了问题。

每当我尝试运行它时,它返回0,而不是233168.

我不一定要寻找一个绝对的答案,只是一些提示,我正在努力学习。

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            List<int> listOne = new List<int>();
            for (x = 1; x < 1000; ++x)
            {
                if(x%3 == 0 || x%5 == 0)
                {
                    listOne.Add(x);
                }
                Console.WriteLine(listOne.Sum());
                Console.ReadLine();
            }
        }
    }
}

1 个答案:

答案 0 :(得分:5)

为了帮助你学习,我不打算提供确切的答案。

查看Console.WriteLine()声明的范围。我的猜测是,当你认为它应该是它时它没有运行。

相关问题