prime number program using c#.net

Prime number program using ASP.Net C#

A prime number can be divided only by itself or by 1 that number is called prime number.

For Example : The number 3 can be divided only by 3 or by 1 that means we say that the number 3 is a prime member.

Noted point:  The number 0 and 1 are not considered prime numbers.

Prime Numbers : 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61..

The live demo example link using JavaScript https://jsfiddle.net/xfpe35tb/

I am going to share the example using Asp.Net C# as given below.

class PrimeNumber
{
    static void Main(string[] args)
    {
        bool IsPrimeNum = true;
        Console.WriteLine("Please enter numbers for get prime number. ");
        long number = Convert.ToInt32(Console.ReadLine());

        for (long p = 2; p <= number; p++)
        {
            for (long q = 2; q <= number; q++)
            {
                if (p != q && p % q == 0)
                {
                    IsPrimeNum = false;
                    break;
                }

            }
            if (IsPrimeNum)
            {
                Console.WriteLine(p);
            }
            IsPrimeNum = true;
        }
        Console.ReadLine();
    }

}

Live output as given below



ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.