Source 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 DynamicSize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int size = Int32.Parse(textBox1.Text);
int[] arr = new int[size];
int i;
for (i = 0; i < arr.Length; i++)
{
string values = Microsoft.VisualBasic.Interaction.InputBox("Enter Value", "Input", "0", 200, 200);
int val = Int32.Parse(values);
arr[i] = val;
}
int k;
if (radioButton1.Checked)
{
listBox1.Items.Clear();
for (i = 0; i < arr.Length; i++)
{
for (k = i + 1; k < arr.Length; k++)
{
if (arr[i] < arr[k])
{
int temp = arr[k];
arr[k] = arr[i];
arr[i] = temp;
}
}
listBox1.Items.Add(arr[i]);
}
}
if (radioButton2.Checked)
{
listBox1.Items.Clear();
int l,m;
for ( l = 0; l < arr.Length; l++)
{
for (m = l + 1; m < arr.Length; m++)
{
if (arr[l] > arr[m])
{
int temp2 = arr[m];
arr[m] = arr[l];
arr[l] = temp2;
}
}
listBox1.Items.Add(arr[l]);
}
}
}
}
}
0 comments :