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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.