Sunday 28 October 2012

Script C# penjumlahan matriks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            //DEKLARASI VARIABLE DAN ARRAY
            int a, b, i, j;
            int baris_a, kolom_a, baris_b, kolom_b;
            int[,] matrik_a;
            int[,] matrik_b;
            byte x;
            //INPUT JUMLAH BARIS DAN KOLOM
            Console.WriteLine();
            Console.Write("<-PROGRAM PENJUMLAHAN MATRIKS->");
            Console.WriteLine();
            Console.WriteLine();
            x = 1;
            while (x >= 1)
            {
                Console.Write("Jumlah Baris Matrik A : ");
                baris_a = int.Parse(Console.ReadLine());
                Console.Write("Jumlah Kolom Matrik A : ");
                kolom_a = int.Parse(Console.ReadLine());
                Console.Write("Jumlah Baris Matrik B : ");
                baris_b = int.Parse(Console.ReadLine());
                Console.Write("Jumlah Kolom Matrik B : ");
                kolom_b = int.Parse(Console.ReadLine());
                Console.WriteLine();
                if (baris_a == baris_b || kolom_a == kolom_b)
                {

                    //ISI ARRAY MATRIKS

                    matrik_a = new int[baris_a, kolom_a];
                    matrik_b = new int[baris_b, kolom_b];

                    Console.WriteLine(" Nilai Matriks A : ");
                    Console.WriteLine("--------------- ");
                    Console.WriteLine();
                    Console.WriteLine();
                    for (a = 0; a < baris_a; a++)
                    {
                        for (b = 0; b < kolom_a; b++)
                        {
                            Console.Write(" Matriks A [" +
                            (a + 1) + " , " + (b + 1) + " ] = ");

                            matrik_a[a, b] = int.Parse(Console.ReadLine());
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine(" Nilai Matriks B : ");
                    Console.WriteLine("--------------- ");
                    Console.WriteLine();
                    Console.WriteLine();
                    for (i = 0; i < baris_b; i++)
                    {
                        for (j = 0; j < kolom_b; j++)
                        {
                            Console.Write(" Matriks B [" + (i + 1) + " , " + (j + 1) + " ] = ");
                            matrik_b[i, j] = int.Parse(Console.ReadLine());
                        }
                    }


                    //HASIL JUMLAH MATRIK A & B
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine(" HASIL PENJUMLAHAN MATRIKS A & B =");
                    Console.WriteLine("------------------------------------ ");
                    Console.WriteLine();
                    for (a = 0; a < baris_a; a++)
                    {
                        for (b = 0; b < kolom_a; b++)
                        {
                            Console.Write(matrik_a[a, b] + matrik_b[a, b]
                            + " ");
                        }
                        Console.WriteLine();
                    }

                    {

                        Console.ReadKey();
                        break;
                    }

                }
                Console.ReadLine();
            }

        }


    }
}

0 komentar:

Post a Comment

Note: only a member of this blog may post a comment.