0% found this document useful (0 votes)
19 views

Alumnos: Deisy Acosta, Selvin Erazo Algoritmo Con Arreglo

The document contains C# code that defines a 2D string array to store country names and populations. It loads country options into a combo box, populates a list box and data grid with selected country data from the array, and calculates the total population displayed in a label. When a button is clicked, it clears existing controls and loops through the array based on the selected combo box index, adding each country name and population to the respective controls and summing the populations.

Uploaded by

Selvin Erazo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Alumnos: Deisy Acosta, Selvin Erazo Algoritmo Con Arreglo

The document contains C# code that defines a 2D string array to store country names and populations. It loads country options into a combo box, populates a list box and data grid with selected country data from the array, and calculates the total population displayed in a label. When a button is clicked, it clears existing controls and loops through the array based on the selected combo box index, adding each country name and population to the respective controls and summing the populations.

Uploaded by

Selvin Erazo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Alumnos: Deisy Acosta, Selvin Erazo

Algoritmo con Arreglo


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Arreglo
{
public partial class Form1 : Form
{
string[,] arreglo = new string[5,2] { { "Guatemala","100" }, { "El Salvador", "150"}, {
"Honduras", "100" }, { "Nicaragua", "200" }, { "Costa Rica", "100" } };

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
comboBox1.SelectedIndex = 0;
}

private void button1_Click(object sender, EventArgs e)


{
listBox1.Items.Clear();
comboBox2.Items.Clear();
dataGridView1.Rows.Clear();
lblconteo.Text = "";

for (int i= 1; i <= Convert.ToInt32(comboBox1.Text); i++)


{
comboBox2.Items.Add(arreglo[i-1,0]);
listBox1.Items.Add(arreglo[i - 1,0]);
dataGridView1.Rows.Add(arreglo[i - 1,0], arreglo[i - 1, 1]);
}

decimal Total = 0;

foreach (DataGridViewRow row in dataGridView1.Rows)


{
Total += Convert.ToDecimal(row.Cells["habitantes"].Value);
}

lblconteo.Text = "La suma de habitantes es: " + Total.ToString();


}
}
}

You might also like