Pages

Subscribe:

Selamat Datang

Terima Kasih telah Mengunjungi Blog saya

Minggu, 25 Januari 2015

Program Matrik

C++ :


#include 
#include 
using namespace std;

class matrix
{
public :
    int matrik [4][4];
    void hitung_matrix()
    {
        int baris, kolom;
        for (baris = 0; baris < 4; baris++)
        {
            for (kolom = 0; kolom < 4; kolom++)
            {
                cout <<"Masukkan baris ke " << baris << " dan kolom ke " << kolom << " : ";
                cin >> matrik[baris][kolom];
            }
        }
        for (baris = 0; baris < 4; baris++)
        {
            for (kolom = 0; kolom < 4; kolom++)
            {
                cout << matrik[baris][kolom] << " ";
            }
            cout<<"\n";
        }
    }
};

int main()
{
    matrix mkn;
    mkn.hitung_matrix();
    getch();
    return 0;
}


CSharp :




using System;

namespace matrik
{
 class Program
 {
  public static void Main(string[] args)
  {
   //Deklarasi Array 2 Dimensi
   
   int [,] matrik = new int[4,4];
   
   // Matrik
   int baris , kolom;
   for( baris = 0 ; baris < 4 ; baris++ ) //Baris
   {
    for(kolom = 0 ; kolom < 4 ; kolom++ ) //Kolom
    {
     Console.Write("Masukkan baris ke " + baris + " dan kolom ke " + kolom + " : ");
     matrik[baris,kolom] = int.Parse(Console.ReadLine());
    } 
   }
   //Menampilkan Inputan Nilai Matrik
   for(baris = 0 ; baris < 4 ; baris++ )
   {
    for( kolom = 0 ; kolom < 4 ; kolom++ )
    {
     Console.Write(matrik[baris,kolom] + " ");
    } 
    Console.WriteLine();
   }
   
   Console.Write("Press any key to continue . . . ");
   Console.ReadKey(true);
  }
 }
}

Java :


package matrix;
import java.util.Scanner;
public class Matrix {
    Scanner Scanner;
    Scanner scn = new Scanner(System.in);
    
    int matrik [][] = new int[4][4];
    public void hitung_matrix()
    {
        int baris, kolom;
        for (baris = 0 ; baris < 4 ; baris++)
        {
            for (kolom = 0 ; kolom < 4 ; kolom++)
            {
                System.out.print("Masukkan baris ke " + baris + " dan kolom ke " + kolom + " : ");
  matrik[baris][kolom] = scn.nextInt();
            }
        }
        for (baris = 0 ; baris < 4 ; baris++)
        {
            for (kolom = 0 ; kolom < 4 ; kolom++)
            {
                System.out.print(matrik[baris][kolom]+ " ");
            }
            System.out.println();
        }   
    } 
    public static void main(String[] args) {
        Matrix m = new Matrix();
        m.hitung_matrix();      
    }
}


Terima Kasih...
Semoga bermanfaat....

0 komentar:

Posting Komentar