Project Euler Problem 7 Solution in C#

Do you need “Project Euler Problem 7 Solution C#”? We will discuss all the problems in Project Euler and try to solve them using Python or C#. I have solved Project Euler Problem 6 Python as well.

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

So we have to solve this problem using C#.

Lets first of all open Visual Studio.

If we analyze the problem statement given here, we can see that we are asked to find 10001st Prime Number

Project Euler Problem 7 Solution C#

Let us start! 

The first thought that came across my mind is Brute Force!

Yes right. So let’s create a while loop taking number one plus each time and checking for prime number. If the number is prime just update a counter. And upon reaching 10001st prime number we stop and print the prime number.

A prime number is that don’t get divided by 1 or itself. If it gets fully divided by 1 or itself then it is not a prime number.

For big numbers, we can use this mathematics rule that if the number does not divide up to its square root then it will never

//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

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

namespace Rextester
    public class Program
        public static void Main(string[] args)
            int count = 0;
            int num = 2;
                if(isPrime(num)) count++;
                if(count == 10001) break;
            //Your code goes here
            Console.WriteLine("Hello, world!");
        static bool isPrime(int num){
            for (int i = 2; i < num; i++){
                if(num % i == 0) return false;
            return true;

Let us see if we got it right.

Project Euler Problem 7 Solution c#
Project Euler Problem 7 Solution c#

Yaay! We got this right. Thanks for reading.

project euler problem 8 solution javascript

Happy coding!


I am a Software Engineer with ample experience in making games, websites, mobile apps and augmented reality solutions.

Pin It on Pinterest