using System;
using System.Collections.Generic;
using System.Text;
namespace mergsortarray
{
class Program
{
static void Main (string[] args)
{
int i, j, t = 0;
Console.WriteLine("enter size of 1st array");
int n1=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter size of 2nd array");
int n2 = Convert.ToInt32(Console.ReadLine());
int n3 = n1 + n2;
int[] a = new int[n1];
int[] b = new int[n2];
int[] c = new int[n3];
Console.WriteLine("enter "+n1+ "int value for 1st array");
for (i = 0; i < n1; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(" enter"+n2+" value for 2nd array");
for (i = 0; i < n2; i++)
{
b[i] = Convert.ToInt32(Console.ReadLine());
}
i = 0;
for (j = 0; j < n3; j++)
{
if (i < n1)
c[i] = a[i];
else c[i] = b[j-n1];
i++;
}
for (j = 0; j < n3; j++)
{
for (i = j; i < n3; i++)
if (c[j] >= c[i])
{
t = c[j];
c[j] = c[i];
c[i] = t;
}
}
Console.WriteLine("merge and sorted array");
for (i = 0; i < n3; i++)
Console.WriteLine(c[i]);
Console.ReadLine();
}
}
}
No comments:
Post a Comment