maxresdefault 43

Ejercicio 16.- Combinar 2 arreglos en C# [45]

En este ejercicio vamos combinar 2 arreglos en un tercer arreglo en C# de la siguiente forma.

  • Declararemos 3 arreglos a,b y c donde a y b tendrán un tamaño de 5 y c tendrá un tamaño de 10.
  • Crearemos dos bucles de 0 a 4 donde pediremos al humano que ingrese los valores del arreglo “a” y “b” respectivamente.
  • Con un tercer bucle llenaremos el tercer arreglo “c” que contendrá la combinación de a y b.
  • Mostraremos el arreglo “c”.
Combinar 2 arreglos en C#

Codigo: https://github.com/programadornovato/-CURSO–C-/commit/e6cd50ce79757af4aa7e230e3b0fbc943d45371f

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic;
/*
Autor: Programador novato
Fecha: 01/01/2021
Este programa hace que los novatos aprenden a hacer
un codigo bonito y ya
*/
namespace HolaMundo
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
int[] b = new int[5];
int[] c = new int[10];
int j = 0;
for (int i = 0; i < 5; i++) {
a[i]=int.Parse(Interaction.InputBox("Humano ingresa el elemento del arreglo a["+(i+1)+"] "));
}
for (int i = 0; i < 5; i++) {
b[i]=int.Parse(Interaction.InputBox("Humano ingresa el elemento del arreglo b["+(i+1)+"] "));
}
for (int i = 0; i < 5; i++) {
c[j] = a[i];
j++;
c[j] = b[i];
j++;
}
string arreglo = "";
foreach (int elemento in c) {
arreglo = arreglo +"\n"+ elemento;
}
MessageBox.Show(arreglo);
}
}
}
using System; using System.Windows.Forms; using Microsoft.VisualBasic; /* Autor: Programador novato Fecha: 01/01/2021 Este programa hace que los novatos aprenden a hacer un codigo bonito y ya */ namespace HolaMundo { class Program { static void Main(string[] args) { int[] a = new int[5]; int[] b = new int[5]; int[] c = new int[10]; int j = 0; for (int i = 0; i < 5; i++) { a[i]=int.Parse(Interaction.InputBox("Humano ingresa el elemento del arreglo a["+(i+1)+"] ")); } for (int i = 0; i < 5; i++) { b[i]=int.Parse(Interaction.InputBox("Humano ingresa el elemento del arreglo b["+(i+1)+"] ")); } for (int i = 0; i < 5; i++) { c[j] = a[i]; j++; c[j] = b[i]; j++; } string arreglo = ""; foreach (int elemento in c) { arreglo = arreglo +"\n"+ elemento; } MessageBox.Show(arreglo); } } }
using System;
using System.Windows.Forms;
using Microsoft.VisualBasic;
/*
Autor: Programador novato
Fecha: 01/01/2021
Este programa hace que los novatos aprenden a hacer
un codigo bonito y ya
*/
namespace HolaMundo
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[5];
            int[] b = new int[5];
            int[] c = new int[10];
            int j = 0;
            for (int i = 0; i < 5; i++) {
                a[i]=int.Parse(Interaction.InputBox("Humano ingresa el elemento del arreglo a["+(i+1)+"] "));
            }
            for (int i = 0; i < 5; i++) {
                b[i]=int.Parse(Interaction.InputBox("Humano ingresa el elemento del arreglo b["+(i+1)+"] "));
            }
            for (int i = 0; i < 5; i++) {
                c[j] = a[i];
                j++;
                c[j] = b[i];
                j++;
            }
            string arreglo = "";
            foreach (int elemento in c) {
                arreglo = arreglo +"\n"+ elemento;
            }
            MessageBox.Show(arreglo);
        }
    }
}

🎦 [CURSO] C#: https://www.youtube.com/watch?v=NKPMGY6NCko&list=PLCTD_CpMeEKQSOU8Vf9VHXrZa2rc8X0X5&ab_channel=programadornovato
🎦 [CURSO] C++ DE 0 A HEROE 🦸: https://www.youtube.com/watch?v=APN8aCyPvww&list=PLCTD_CpMeEKTofxs7iottRxJ5YPM7BOcc&ab_channel=programadornovato
🎦 [Curso] Java Netbeans Completo☕: https://www.youtube.com/watch?v=97nO4-zdviA&list=PLCTD_CpMeEKTT-qEHGqZH3fkBgXH4GOTF&ab_channel=programadornovato

🔗 Canal de ProgramadorNovato: https://www.youtube.com/c/programadornovato
🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial
🔗 Twitter: https://twitter.com/programadornova
🔗 Linkedin: https://www.linkedin.com/in/programadornovato/
🔗 Instagram: https://www.instagram.com/programadornovato/
🔗 Pagina oficial: https://www.programadornovato.com
🔗 Gracias por apoyar este canal: https://www.patreon.com/programadornovato

Anterior tutorial Siguiente tutorial

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *