I was able to solve Problem 1 pretty quickly. I am going to use C# to solve these problems. It is probably not the most elegant code, but if you know me that probably does not surprise... Here is the source to problem 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ProjectEularProb1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List
bool alreadyThere = false;
private void button1_Click(object sender, EventArgs e)
{
List
numbs.Add(3);
numbs.Add(5);
foreach (int x in numbs)
{
FindMultiplesUnderAG(x);
}
textBox1.Text = numlist.Sum().ToString();
}
private void FindMultiplesUnderAG(int x)
{
int y = 0;
for (int i = 0; i <= 1000; i++)
{
y = i * x;
if (y < 1000)
{
foreach (int z in numlist)
{
if (y == z)
{
alreadyThere = true;
}
}
if(alreadyThere.Equals(false))
{
numlist.Add(y);
listBox1.Items.Add(y);
}
alreadyThere = false;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
listBox1.Items.Clear();
numlist.Clear();
}
}
}
No comments:
Post a Comment