Wednesday, August 11, 2010

Program to demonstrate a single dimension array.


Write a program to demonstrate a single dimension array.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Arrays
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            Console.WriteLine("Enter the Lenght of array");
            a = Convert.ToInt32(Console.ReadLine());
            int[] m = new int[a];
            int[] n = new int[a];
            Console.WriteLine("Enter the elements of array1");
            for (int i = 0; i < a; i++)
            {
                m[i] = Convert.ToInt32(Console.ReadLine());
            }
            Console.WriteLine("Enter the elements of array2");
            for (int i = 0; i < a; i++)
            {
                n[i] = Convert.ToInt32(Console.ReadLine());
            }
            Console.WriteLine("The elements of arrays are");
            for (int i = 0; i < a; i++)
            {
                Console.WriteLine("{0}\t+\t{1}\t\t{2}", m[i],n[i],m[i]+n[i]);
            }
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment