Ejemplo: Mostrar los números pares entre el 0 y el 100


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ejemplo_13
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, impar = 0, par = 0;

            for (i = 1; i < 100; i++)
            {
                if (i % 2 == 0)
                {
                    Console.Write("{0}|", i);
                    par++;
                }
            }
            Console.Write("\n\nDel 0 al 100 hay {0} números pares y {1} impares\n\n", par, impar);

            Console.Read();
        }
    }
}


Ejemplo: Mostrar los números impares entre el 0 y el 100


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ejemplo_12
{
    class Program
    {
        static void Main(string[] args)
        {

            int i, impar = 0, par = 0;

            for (i = 0; i < 100; i++)
            {
                if (i % 2 != 0)
                {
                    Console.Write("{0}|", i);
                    impar++;
                }
            }

            Console.Write("\n\n");

            Console.Read();
        }
    }
}



Resta de 2 números enteros en - C# aplicación

Realizar una aplicación para restar dos números enteros.



CÓDIGO FUENTE

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

namespace Resta
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n1 = int.Parse(textBox1.Text);
            int n2 = int.Parse(textBox2.Text);

            int resta = n1 - n2;

            textBox3.Text = resta.ToString();

        }


        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox1.Focus();

        }


        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }


    }
}

Suma de 2 números C# - Aplicación

Realizar una aplicación para sumar 2 números enteros.


CÓDIGO FUENTE


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

namespace Suma
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n1 = int.Parse(textBox1.Text);
            int n2 = int.Parse(textBox2.Text);
            
            int suma = n1 + n2;
            
            textBox3.Text = suma.ToString();

        }


        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox1.Focus();

        }

        
        private void button3_Click(object sender, EventArgs e)
        {
            Close();   
        }
    }
}


Realizar un programa para convertir grados Celsius a Fahrenheit



CODIGO FUENTE

using System;
using System.Collections.Generic;
using System.Text;

namespace Ejemplo_18
{
    class Program
    {
        static void Main(string[] args)
        {
           Console.WriteLine("Ingresa Grados Centigrados");
         
           double c = Convert.ToDouble(Console.ReadLine());
         
           double f = (c * 9 / 5) + (32);
         
           Console.WriteLine(c + "ºC equivale a " + f + "ºF");
         
           Console.ReadLine();
        }
    }
}






Matriz de N x M llenado con numeros aleatorios - C#

Realizar un programa que ingrese una matriz de N x M con números generados aleatoriamente.



CODIGO FUENTE

using System;
using System.Collections.Generic;
using System.Text;

namespace Ejemplo_17
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Matriz de:");
            int a = int.Parse(Console.ReadLine());

            Console.WriteLine("Matriz por:");
            int b = int.Parse(Console.ReadLine());

            int[,] bidimencion;
            bidimencion = new int[a, b];

            Random numero = new Random();

            // Llenando de la matriz con numero aleatorios entre 1 y 100
            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < b; j++)
                {

                    bidimencion[i, j] = numero.Next(1, 100);
                }
            }
            Console.WriteLine("Impresion de la matriz");
         
            // Impresion de la matriz
            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < b; j++)
                {
                    Console.Write(bidimencion[i, j]);
                    if (j + 1 == b) { Console.WriteLine(); } else { Console.Write(" - "); }
                }
            }
            Console.ReadKey(true);
        }
    }
}



Área del triangulo - C#

Realizar un programa para calcular el área de un triangulo en C#


CODIGO FUENTE

using System;
using System.Collections.Generic;
using System.Text;

namespace Ejemplo_15
{
    class Program
    {
        static void Main(string[] args)
        {
            double b, h, a;
            Console.WriteLine("Ingresa base");
            // ENTRADA
            b = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Ingresa altura");
            h = Convert.ToDouble(Console.ReadLine());
            // PROCESO
            a = b * h / 2;
            // SALIDA
            Console.WriteLine("El área del triangulo es");
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}

 CLIC PARA DESCARGAR



Popular Posts