Tuesday, 28 February 2012

Check Given No Prime or Not Prime




// Program for prime no



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace primeNo
{

    public partial class Form1 : Form
    {
        int i;

        public Form1()
        {
            InitializeComponent();
        }
      private void btnprime_Click(object sender, EventArgs e)
        {
            int n = Convert.ToInt32(txtno.Text);
            if (n == 1)
            {
                MessageBox.Show(n + "is not Prime");
            }
            for (i = 2; i < n; i++)
            {
                if (n % i == 0)
                {
                    MessageBox.Show(n + "-is not Prime");
                    break;
                }
            }
            //if (i ==n)
            if (i % n == 0)
            {
                MessageBox.Show(n + "is Prime");
            }
        }

        private void btneven_Click(object sender, EventArgs e)
        {
            int n = Convert.ToInt32(txtno.Text);
            if (n == 1)
            {
                MessageBox.Show(n +     "is Odd No ");
            }
            if (n % 2 == 0)
            {
                MessageBox.Show(n +      "is Even ");

            }
            else
            {
                MessageBox.Show(n +     "is not Even ");
            }
       
        }

        private void btnodd_Click(object sender, EventArgs e)
        {
            int n = Convert.ToInt32(txtno.Text);
            if (n == 1)
            {
                MessageBox.Show(n + "is  1 ");
            }

            if (n % 2 == 0)
            {
                MessageBox.Show(n + "is Odd ");

            }
            else
            {
                MessageBox.Show(n + "is not Odd ");
            }
        }
    }
}






0 comments:

Post a Comment