Thursday, 19 September 2013

Console Application : Prime Number

Prime Number are the Numbers Which Are Those Number Which are Divisible By 1 And Only Those Number. Eg . 5 which is Divisible By 1 And 5 Only.

Create New Console Application Program And Name It as primeno
Replace Your Program.cs with below Code.

Program.cs



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

namespace primeno
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, f = 0;
            Console.WriteLine("Enter Any No. :");
            n = Int32.Parse(Console.ReadLine());
            for (int i = 2; i < n; i++)
            {
                if (n % i == 0)
                    f = 1;
            }

            if (f == 0)
                Console.WriteLine("Given no. "+n+" Is a Prime Number");
            else
                Console.WriteLine("Given no. " + n + " Is Not a Prime Number");

            Console.ReadKey();
        }
    }
}

Ww Will Take the Input Number In integer 'n' and then we will try to devide it by every possible number which are minimum than input number.

Now Compile And Run Your Project And Enter Any Number And Check Whether It is Prime Number Or Not.
My Output's Are as Below






 


 All The Best :)


 

No comments:

Post a Comment