Output:
Code:
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 Question_9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 0;
int[] no = new int[5];
//Insert 5 Number
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
if (i < no.Length)
{
no[i] = Int32.Parse(textBox1.Text);
textBox1.Text = " ";
i++;
}
else
{
MessageBox.Show("Array Index out of Bounds Exception");
textBox1.Clear();
}
}
}
//show Button
private void button2_Click(object sender, EventArgs e)
{
for (i = 0; i < 5; i++)
{
label2.Text += no[i] + " ";
}
sort1(no);
maximum(no);
minimum(no);
}
public void sort1(int[] x)
{
Array.Sort(x);
for (i = 0; i < 5; i++)
{
label3.Text += x[i] + " ";
}
}
public void maximum(int[] x)
{
int maxno = x[0];
for (i = 0; i < 5; i++)
{
if (maxno < x[i])
{
maxno = x[i];
}
}
label4.Text = "Maximum :"maxno.ToString();
}
public void minimum(int[] x)
{
int maxno = x[0];
for (i = 0; i < 5; i++)
{
if (maxno > x[i])
{
maxno = x[i];
}
}
label5.Text = maxno.ToString();
}
}
}
No comments:
Post a Comment