using System;

namespace TallerMatrices
{
    class Program
    {
        static void Main(string[] args)
        {
			Console.WriteLine(">--> 5.	Llevar los elementos de la diagonal principal y la diagonal secundaria de una matriz \nde NxN a un vector de 2N posiciones. Imprimirlos en orden ascendente.");
            Random aleatorio = new Random();
            Console.Write("\nIngrese el # filas de la matriz [N] : ");
            int N = Convert.ToInt32(Console.ReadLine());
            int[,] matriz = new int[N, N];
            int[] vector = new int[2 * N];

            Console.WriteLine("\n--> MATRIZ ORIGINAL <--");
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    matriz[i, j] = aleatorio.Next(100, 1000);
                    Console.Write($"  {matriz[i, j]} ");             
                }
                Console.WriteLine("");
            }
            
            int p = 0;
            for (int i = 0; i < N; i++)
            {
                vector[p] = matriz[i, i];   //Llevar diagonal principal
                p++;
            }
            for (int i = 0; i < N; i++)
            {
                vector[p] = matriz[i, N-i-1];   //Llevar diagonal secundaria
                p++;
            }
            Console.WriteLine("\n--> VECTOR UNIÓN <--");
            for (int i = 0; i < N*2; i++)
            {
                Console.Write($" {vector[i]} ");                
            }
            Console.WriteLine("\n");
		}
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: