I am beginning to feel as if my head is full of mush every time I have to deal with a jagged array in a loop. I stole the solution from here, but the code is entirely my own. In short, you begin at the bottom-left corner of the jagged array. You move to the [...]
This was a question of two parts: Calculate the next triangle number in sequence. Take said triangle number and calculate how many divisors it has. Loop until you find one with 500, and break. The first part was simple: Start with n = 1. For every iteration of the loop, add n to n, and [...]
using System; public class Six { static void Main() { double a = 100; double b = 0; double c = 0; for (int i = 1; i < = a; i++) { b += (i * i); c += i; } c = c * c; if (b > c) Console.WriteLine(“n{0}n”, b – c); [...]
using System; public class Five { static void Main() { int a = 20; int b = 0; while (b < = 0) { for (int i = 11; i < 20; i++) { if (a % i != 0) { a += 20; break; } else if (i == 19) { b = a; [...]
using System; public class Four { static void Main() { int a = 0; int b = -1; int c = 999; for (int i = 100; i < = c; i++) { for (int j = 100; j <= c; j++) { a = i * j; if ((a == Reverse(a)) && (a > [...]
using System; public class Three { static void Main() { long a = 600851475143; int b = Convert.ToInt32(Math.Sqrt(a)); int c = 0; for (int i = b; i >= 2; i–) { if (a % i == 0) if (ChkPrime(i)) { c = i; break; } } Console.WriteLine(“n{0}n”, c); } static bool ChkPrime(int c) { [...]
using System; public class Two { static void Main() { int a = 1; int b = 1; int c = 0; int sum = 0; int cap = 4000000; do { c = a + b; if (c % 2 == 0) sum += c; a = b; b = c; } while (c [...]