koding C# Array
Array 2 demensi
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace desember30_2
{
class Program
{
static void Main(string[]
args)
{
objekarray();
matri2d();
Console.ReadLine();
}
static void objekarray()
{
Console.WriteLine("arrray dengan objek");
DataTable
table = gettable();
object[]
myobjek = new object[4];
myobjek[0] = 10;
myobjek[1] = "ama";
myobjek[2] = "MA211";
myobjek[3] = "B";
//
myobjek[2] = new DateTime(2014, 8, 19);
table.Rows.Add(myobjek);
Console.WriteLine("NIM|\tNama|\tKode|\tNilai");
Console.WriteLine("---------------------------------");
for
(int i = 0; i < 4; i++)
{
Console.Write(myobjek[i]
+ "\t");
}
}
static DataTable gettable()
{
DataTable
table = new DataTable();
table.Columns.Add("Nim", typeof(int));
table.Columns.Add("Nama Mahasiswa", typeof(string));
table.Columns.Add("Kode MTK", typeof(string));
table.Columns.Add("Nilai", typeof(char));
return
table;
}
static void matri2d()
{
Console.WriteLine();
Console.WriteLine("Matrik 2 dimensi ");
int[,]
mymatriks;
Console.WriteLine();
Console.Write("Baris : ");
int
b = int.Parse(Console.ReadLine());
Console.Write("Kolom : ");
int
k = int.Parse(Console.ReadLine());
Console.WriteLine();
mymatriks = new int[b, k];
//
mengisi matrik
for
(int i = 0; i < b; i++)
{
for
(int j = 0; j < k; j++)
{
Console.Write("baris " +i+ "
kolom "+j+ " = ");
mymatriks[i, j] = int.Parse(Console.ReadLine());
}
}
//
mencetak matrik
Console.WriteLine();
for
(int i = 0; i < b; i++)
{
for
(int j = 0; j < k; j++)
{
Console.Write(mymatriks[i,j]+
"\t");
}
Console.WriteLine();
Console.WriteLine();
}
Console.ReadLine();
}
}
}
0 komentar: