Objective:
Take 10 inputs from the user and assign them into
two arrays (make 2 arrays of 5 lengths each), merge those arrays and obtain the
result in the sorted manner.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Merg
{
class Program
{
static void Main(string[] args)
{
int[] Ary1 = new int[5];
Console.WriteLine("Enter
the 5 values of First Array array");
for (int i = 0; i
< 5; i++)
{
Ary1[i] = int.Parse(Console.ReadLine());
}
int[] Ary2 = new int[5];
Console.WriteLine("Enter
the 5 values of Second array");
for (int i = 0; i
< 5; i++)
{
Ary2[i] = int.Parse(Console.ReadLine());
}
int[] Ary = new int[Ary1.Length + Ary2.Length];
Ary1.CopyTo(Ary, 0);
Ary2.CopyTo(Ary, Ary1.Length);
for (int i = 0; i
< 9; i++)
{
int min = i;
for (int
j = i + 1; j < 10; j++)
{
if (Ary[j] < Ary[min])
{
min = j;
}
}
}
Console.WriteLine("Sorting values by using merg sort");
for (int i = 0; i
< 10; i++)
{
Console.Write("{0}",Ary[i]);
Console.Write(" ");
}
}
}
}
Output: