Está en la página 1de 2

class Program

{
static int tamA, tamB,tamC;
static int[] A, B, C;
static void Main(string[] args)
{
CrearArregloA();
CrearArregloB();
JuntarArreglos();
OrdenarArreglo();
PresentarArreglo();
}
static void CrearArregloA()
{
Console.WriteLine("¿Cuantos elementos tendra el conjunto A?");
tamA = int.Parse(Console.ReadLine());
A = new int[tamA];
Console.WriteLine("Señale los elementos de A: ");
for (int i = 0; i < tamA; i++)
{
A[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("----------------------------------------");
Console.ReadKey();
}
static void CrearArregloB()
{
Console.WriteLine("¿Cuantos elementos tendra el conjunto B?");
tamB = int.Parse(Console.ReadLine());
B = new int[tamB];
Console.WriteLine("Señale los elementos de B: ");
for (int i = 0; i < tamB; i++)
{
B[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("----------------------------------------");
Console.ReadKey();
}
static void JuntarArreglos()
{
tamC = tamA + tamB;
C = new int[tamC];
for(int i =0;i<tamA;i++)
{
C[i] = A[i];
}
for(int j=0;j<tamB;j++)
{
C[j + tamA] = B[j];
}
Console.WriteLine("Los elemenots del conjunto C son:");
for (int k = 0; k < tamC; k++)
{
Console.WriteLine("elemento {0} es: {1}", k + 1, C[k]);
}
Console.ReadKey();
}
static void OrdenarArreglo()
{
for (int i = 1; i < tamC; i++)
{
int j = i;
while (j > 0)
{
if (C[j - 1] > C[j])
{
int temp = C[j - 1];
C[j - 1] = C[j];
C[j] = temp;
j--;
}
else
break;
}
}
}
static void PresentarArreglo()
{
Console.WriteLine("-------------------------------------------------");
Console.WriteLine("Ordenando los elementos del conjunto C tendremos:");
for (int k = 0; k < tamC; k++)
{
Console.WriteLine("elemento {0} es: {1}", k + 1, C[k]);
}
Console.ReadKey();
}

}
}

También podría gustarte