Popular Post

Posted by : Unknown jueves, 12 de junio de 2014



En el siguiente ejemplo se pide el ingreso por teclado de un vector a[]; posteriormente se realiza la comparacion de numeros pares e impares separandolos en dos vectores diferentes b[]= pares c[]=impares.
 
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[15];
            int[] b = new int[15];
            int[] c = new int[15];
            int i, j=0, k=0;
            for (i = 0; i < 15; i++)
            {
                Console.Write("a[{0}]=", i);
                a[i] = Convert.ToInt32(Console.ReadLine());
                if (a[i] % 2 == 0 && a[i] != 1)
                {
                    b[j] = a[i];
                    j++;
                }
                else
                {
                    c[k] = a[i];
                    k++;
                }
            }
            for (i = 0; i < 15; i++)
                Console.WriteLine("a[{0}]={1}", i, a[i]);
            for (i = 0; i < j; i++)
                Console.WriteLine("b[{0}]={1}", i, b[i]);
            for (i = 0; i < k; i++)
                Console.WriteLine("c[{0}]={1}", i, c[i]);
            Console.ReadKey();
        }
    }
}

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Programación #5 - Date A Live - Powered by Blogger - Designed by Johanes Djogan -