21 October 2013

Given Number is Prime number or not in C#.Net



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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            Console.WriteLine("Enter a value");
            int x = int.Parse(Console.ReadLine());

            int y = 2;
            if (y <= x / 2)
            {
                if (x % y == 0)
                {
                    count++;
                }
            }
            if (count == 0 && count != 1)
            {
                Console.WriteLine(x + " is Prime Number");
            }
            else
            {
                Console.WriteLine(x + " is not Prime Number");
            }
            Console.ReadLine();
        }
    }
}

Output
 
 

No comments:

Post a Comment