contoh Program penjumlahan Array C#

Program penjumlahan Array C#

Berikut adalah contoh program penjumlahan array dengan menggunakan bahasa pemprogramman C#

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

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

            int[,] array1 = new int[2, 2];
            int[,] array2 = new int[2, 2];
            int[,] arrayhasil = new int[2, 2];
            int x, y;


            for (int a = 0; a < 2; a++)
            {
                for (int b = 0; b < 2; b++)
                {
                    Console.Write("Input nilai dari Array1 " + "[" + a + "][" + b + "] = ");
                    array1[a, b] = int.Parse(Console.ReadLine());
                }
            }

            //Console.Clear();

            for (int c = 0; c < 2; c++)
            {
                for (int d = 0; d < 2; d++)
                {
                    Console.Write("Input nilai dari Array2 " + "[" + c + "][" + d + "] = ");
                    array2[c, d] = int.Parse(Console.ReadLine());
                }
            }

            //Console.Clear();

            for (x = 0; x < 2; x++)
            {
                for (y = 0; y < 2; y++)
                {
                    Console.Write(array1[x, y] + " ");
                }
                Console.WriteLine();
            }

            Console.WriteLine(" +");

            for (x = 0; x < 2; x++)
            {
                for (y = 0; y < 2; y++)
                {
                    Console.Write(array2[x, y] + " ");
                }
                Console.WriteLine();
            }

            Console.WriteLine(" =");

            for (x = 0; x < 2; x++)
            {
                for (y = 0; y < 2; y++)
                {
                    arrayhasil[x, y] = array1[x, y] + array2[x, y];
                }
            }

            for (x = 0; x < 2; x++)
            {
                for (y = 0; y < 2; y++)
                {
                    Console.Write(arrayhasil[x, y] + " ");
                }
                Console.WriteLine();
            }

            Console.ReadKey();
        }
    }
}
C#

Semoga bermanfaat.