Monday, 30 December 2013

Prime Number using Console Application in C#

Ans:-

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

namespace Logicals
{
    class Primenumber
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Number Only..");
            int num = int.Parse(Console.ReadLine());
            int count=0;
            for (int i = 2; i <= num;i++ )
            {
                if (num % i == 0)
                {
                    count++;
                }
                }
            if (count == 1)
            {
                Console.WriteLine("It's a Prime No..");
            }
            else
            {
                Console.WriteLine("It's Not a Prime No..");
            }
                    Console.ReadLine();
        }
    }
}

No comments:

Post a Comment