koding C# Geser Kiri Dan Geser Kanan
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Try
{
class hidayat_maulana_array
{
static void Main(string[] args)
{
Console.WriteLine(" WELCOME IN THE BIG PROGRAM");
Console.WriteLine(" STMIK INDONESIA");
Console.WriteLine("");
Console.Write("Jumlah
Indeks : ");
int n = int.Parse(Console.ReadLine());
input_array(n);
Console.WriteLine();
input_array2(n);
Console.ReadLine();
}
static void
input_array(int n)
{
string[] x = new string[n];
for (int i = 0; i
<= x.Length - 1; i++)
{
Console.Write("Array geser Kiri > masukkan nilai array ke " + i
+ ": ");
string a = Console.ReadLine();
x[i] = a;
}
Console.WriteLine("Proses
array : ");
tampilan_array(x, n);
kiri_array(x, n);
Console.WriteLine("array
geser kiri : ");
tampilan_array(x, n);
}
static void
input_array2(int n)
{
string[] x = new string[n];
for (int i = 0; i <= x.Length - 1; i++)
{
Console.Write("Array geser Kanan > masukkan nilai array ke " + i
+ ": ");
string a = Console.ReadLine();
x[i] = a;
}
Console.WriteLine("Proses
Array : ");
tampilan_array2(x, n);
kanan_array(x, n);
Console.WriteLine("array
geser kanan : ");
tampilan_array2(x, n);
}
static void
tampilan_array(string[] x, int n)
{
Console.WriteLine("Array
: ");
for (int j = 0; j
<= n - 1; j++)
{
Console.WriteLine(x[j]);
}
}
static void
kiri_array(string[] x, int
n)
{
for (int j = 0; j
<= n - 1; j++)
{
if (j == 0)
{
x[j] = "B";
}
{
if (j == 1)
{
x[j] = "C";
}
}
{
if (j == 2)
{
x[j] = "D";
}
}
{
if (j == 3)
{
x[j] = "E";
}
}
{
if (j == 4)
{
x[j] = "F";
}
}
{
if (j
== 5)
{
x[j] = "G";
}
}
{
if (j == 6)
{
x[j] = "A";
}
}
}
tampilan_array(x, n);
}
static void
tampilan_array2(string[] x, int n)
{
Console.WriteLine("Array
: ");
for (int j = 0; j
<= n - 1; j++)
{
Console.WriteLine(x[j]);
}
}
static void
kanan_array(string[] x, int n)
{
for (int j = 0; j
<= n - 1; j++)
{
if (j == 0)
{
x[j] = "G";
}
{
if (j == 1)
{
x[j] = "A";
}
}
{
if (j == 2)
{
x[j] = "B";
}
}
{
if (j == 3)
{
x[j] = "C";
}
}
{
if
(j == 4)
{
x[j] = "D";
}
}
{
if (j == 5)
{
x[j] = "E";
}
}
{
if (j == 6)
{
x[j] = "F";
}
}
}
tampilan_array(x, n);
}
}
}
0 komentar: