17 May 2016 Sudhanshu Ranjan 1.29k

What is Prime Number? Print Prime Number using C#

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.


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

namespace PrimeNumber
    class Program
        static void Main(string[] args)
            Console.WriteLine("Please enter the number in which you want to find the Prime No :");
            int a = Convert.ToInt32(Console.ReadLine());
            bool isPrime = true;

            for (int i = 1; i <= a; i++)
                for (int j = 2; j <= a; j++)
                    if (i != j && i % j == 0)
                        isPrime = false;


                if (isPrime)
                    Console.WriteLine("Prime Number:" + i);

                isPrime = true;



You can share at :

About Author
Sudhanshu Kumar Ranjan | Lead Engineer at HCL Technologies | Expertise in Microsoft Technology | Author | Blogger | Programmer
Know More
Connect with him on Facebook | Google+ | LinkedIn | Twitter

Recommended Post

Leave a comment

About Dotnet Cube

It's my blog - Dotnet Cube, where you will learn and get solutions about programming, web designing and development. I started this website to share my knowledge and experience which might help someone.

You can get more details about me and my blog at About Us page.

Subscribe Newsletter

Subscribe to our monthly newsletter to get the latest industry news, Media Group updates and our current specials.

Follow On Us...

Home | About | Advertise | Copyrights | Privacy | Contact | Admin

Copyrights © 2015-2019 dotnetcube.com. All rights reserved