Berikut adalah contoh Program Penjumlahan Array C++ dengan menggunakan bahasa pemprogramman C++
C++
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Penjumlahan_Array
{
class Program
{
static void Main(string[] args)
{
int[,] matrik1 = new int[2, 2];
int[,] matrik2 = new int[2, 2];
int[,] hasil = 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 matriks1 " + "[" + a + "][" + b + "] = ");
matrik1[a, b] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine();
for (int c = 0; c < 2; c++)
{
for (int d = 0; d < 2; d++)
{
Console.Write("Input nilai matriks2 " + "[" + c + "][" + d + "] = ");
matrik2[c, d] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine();
for (x = 0; x < 2; x++)
{
for (y = 0; y < 2; y++)
{
Console.Write(matrik1[x, y] + " ");
}
Console.WriteLine();
}
Console.WriteLine(" +");
for (x = 0; x < 2; x++)
{
for (y = 0; y < 2; y++)
{
Console.Write(matrik2[x, y] + " ");
}
Console.WriteLine();
}
Console.WriteLine("------HASIL PENJUMLAHAN-----");
for (x = 0; x < 2; x++)
{
for (y = 0; y < 2; y++)
{
hasil[x, y] = matrik1[x, y] + matrik2[x, y];
}
}
for (x = 0; x < 2; x++)
{
for (y = 0; y < 2; y++)
{
Console.Write(hasil[x, y] + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
C++Itulah contoh program penjumlahan array lengkap beserta penjelasan fungsi yang digunakan. Semoga dapat membantu Anda dalam memahami konsep penjumlahan array dalam bahasa pemrograman C++.