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# | **

**Lets start! **

The first thought came across my mind is Brute Force!

Yes right. So lets 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 10001th prime number we stop and print the prime number.

A prime number is that dont 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 upto 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; while(true){ if(isPrime(num)) count++; if(count == 10001) break; num++; } Console.WriteLine(num); //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; } } }

Lets see if we got it right.

Yaay! We got this right. Thanks for reading.

project euler problem 8 solution javascript

Happy coding!

You must log in to post a comment.