Koding C# Array
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace tugas7
{
class Program
{
static void Main(string[]
args)
{
Console.Write("Jumlah Array : ");
int
n = int.Parse(Console.ReadLine());
input(n);
Console.ReadLine();
}
static void input(int n)
{
string[]
x = new string[n];
for
(int i = 0; i < n; i++)
{
Console.Write("Input Array " + i + " : ");
x[i] = Console.ReadLine();
}
Console.WriteLine();
Console.WriteLine("Array :");
cetak(x, n);
kiri(x, n);
kanan(x, n);
}
static void kiri(string[] x,
int n)
{
string[]
kiri = new string[n];
for
(int i = 0; i < n; i++)
{
kiri[i] = x[i];
}
string
temp = kiri[0];
for
(int j = 0; j < n - 1; j++)
{
kiri[j] = kiri[j + 1];
}
kiri[n - 1] = temp;
Console.WriteLine();
Console.WriteLine("Geser Kiri :");
cetak(kiri, n);
}
static void kanan(string[]
x, int n)
{
string[]
kanan = new string[n];
for
(int i = 0; i < n; i++)
{
kanan[i] = x[i];
}
string
temp = kanan[n - 1];
for
(int j = n - 1; j > 0; j--)
{
kanan[j] = kanan[j - 1];
}
kanan[0] = temp;
Console.WriteLine();
Console.WriteLine("Geser Kanan :");
cetak(kanan, n);
}
static void cetak(string[]
array, int n)
{
for
(int i = 0; i < n; i++)
{
Console.Write(array[i]
+ " ");
}
Console.WriteLine();
}
}
}
0 komentar: