Script C# Penjumlahan Matrik:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class
Program
{
static
void Main(string[] args)
{
int[,] matriks = new int[2, 2];
int[,] matrisk2 = new int[2, 2];
int[,] hasil = new int[2, 2];
Console.WriteLine("Masukkan nilai matriks");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
Console.Write("matriks[{0}, {1}]= ", i + 1, j + 1);
matriks[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine();
Console.WriteLine("Masukkan nilai matriks 2");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
Console.Write("matriks2[{0}, {1}]= ", i + 1, j + 1);
matrisk2[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine();
Console.WriteLine("Menampilkan nilai matriks");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
Console.Write("{0} ", matriks[i, j]);
}
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine("Menampilkan nilai matriks2");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
Console.Write("{0} ", matrisk2[i, j]);
}
Console.WriteLine();
}
Console.WriteLine();
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
hasil[i, j] = matriks[i, j] + matrisk2[i, j];
}
}
Console.WriteLine("Menampilkan hasil penjumlahan 2 matrix");
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
Console.Write("{0} + {1} = {2} ", matriks[i, j], matrisk2[i,
j], hasil[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Tidak ada komentar:
Posting Komentar