TheDezzick
TheDezzick

Reputation: 1

Project Euler #4 in C#

I'm attempting to do Project Euler problem #4 in C#. The problem I'm having is that when the code runs a console window briefly appears and then goes away. I don't know what the problem could be as I'm relatively new to programming.

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1000; i > 100; i--)
                for (int j = 1000; j > 100; j--)
                    PalCheck(i * j);
        }

        static void PalCheck(int original)
        {
            var reversed = new string(Convert.ToString(original).ToCharArray().Reverse().ToArray());

            if (Convert.ToString(original) == reversed)
                Console.WriteLine(original);

            Console.ReadKey();
        }
    }
}

Upvotes: 0

Views: 288

Answers (1)

Deepansh Gupta
Deepansh Gupta

Reputation: 593

The code seems to be stuck at the line Console.ReadKey() as at this line of code, the program is waiting for some input key. Since you have not used any message before ReadKey(), you don't realize that the program is waiting for some input and not stuck.

Move Console.ReadKey() after PalCheck(i * j) and you should see the output on the console screen.

Upvotes: 1

Related Questions