Array 2 Dimensi

Contoh Proggram aray 2 Dinamis

–          C#

<pre>
using System;

using System.Security.Cryptography.X509Certificates;

&nbsp;

namespace csharp_array_2D

{

class Program

{

private static byte banyak(string a)

{

byte data;

Console.Write(a);

data=Convert.ToByte(Console.ReadLine());

return data;

}

private static byte[,] arr(byte a,byte b)

{

byte[,] data= new byte[a,b];

for (int i = 0; i < a; i++) {

for (int x = 0; x < b; x++) {

Console.Write("Data ke [{0}],[{1}] = ",i,x);

data[i,x]=Convert.ToByte(Console.ReadLine());

}

}

return data;

}

private static void tampil(byte [,] a,byte b,byte c)

{

for (int i = 0; i < b; i++) {

for (int x = 0; x < c; x++) {

Console.WriteLine("Besar data ke [{0}],[{1}] = {2}",i,x,a[i,x]);

}

}

}

public static void Main(string[] args)

{

byte a,b;

a=banyak("baris = ");

b=banyak("kolom = ");

byte[,]data=new byte[a,b];

data=arr(a,b);

tampil(data,a,b);

Console.Write("Press any key to continue . . . ");

Console.ReadKey(true);

}

}

}

hasilnya :

–          C++


#include <cstdlib>

#include <iostream>

using namespace std;

int input(string a)

{

int data;

cout<<a;

cin>>data;

return data;

}

void arr(int a,int b)

{

int data [a][b];

for (int i=0;i<a;i++)

{

for (int x=0;x<b;x++)

{

cout<<"Data {"<<i<<"},{"<<x<<"} = ";

cin>>data[i][x];

}

}

&nbsp;

for (int j=0;j<a;j++)

{

for (int z=0;z<b;z++)

{

cout<<"Besar Data {"<<j<<"},("<<z<<"} = "<<data[j][z]<<endl;

}

}

}

int main(int argc, char *argv[])

{

int a,b;

a=input("baris = ");

b=input("kolom = ");

arr(a,b);

system("PAUSE");

return EXIT_SUCCESS;

}

Hasil :

–          Java


package dimen;

import java.util.Scanner;

&nbsp;

public class Main {

public static Scanner input = new Scanner(System.in);

static byte banyak(String a)

{

byte data;

System.out.print(a);

data=input.nextByte();

return data;

}

static byte [][]arr(byte a,byte b)

{

byte [][]data=new byte[a][b];

for (byte i=0;i<a;i++)

{

for (byte x=0;x<b;x++)

{

System.out.print("Data ke {"+i+"},{"+x+"} = ");

data[i][x]=input.nextByte();

}

}

return data;

}

static void  tampil(byte [][] a, byte b,byte c)

{

for (byte i = 0; i < b; i++)

{

for (byte j = 0; j < c;j++)

{

System.out.println("Banyak Data ke {"+i+"},{"+j+"} = "+a[i][j]);

}

}

}

public static void main(String[] args) {

byte a,b;

a=banyak("baris = ");

b=banyak("kolom = ");

byte[][]data=new byte[b][b];

data=arr(a, b);

tampil(data, b, b);

}

&nbsp;

}

Hasil:

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s