You are on page 1of 13

NAMA :RIDHATUR ROHMAT

NIM :18104410063
KELAS :TI C

MODUL 3

Tugas Praktikum
1. Buatlah program menggunakan Nested Loop!
a.
//RIDHATUR ROHMAT

using System;
using System.Collections.Generic;

using System.Linq;

using System.Text;
using System.Threading.Tasks;

namespace Tugas1a
{

class Program
{

static void Main(string[] args)


{

string kata;

string[] olahkata;

Console.Write("Input\t : ");

kata = Convert.ToString(Console.ReadLine());

olahkata = new string[kata.Length];

for (int i = 0; i < (kata.Length); i += 1)


{

olahkata[i] = kata.Substring(kata.Length - (i + 1), 1);

Console.Write("Output\t : ");

for (int i = 0; i < (kata.Length); i++)


{

Console.Write(olahkata[i]);

}
Console.ReadLine();

b.

//RIDHATUR ROHMAT

using System;

using System.Collections.Generic;

using System.Linq;
using System.Text;

using System.Threading.Tasks;

namespace Tugas1b
{

class Program
{

static void Main(string[] args)


{

int bil, a = 0;

Console.Write(" Masukkan Bilangan : ");

bil = Convert.ToInt32(Console.ReadLine());

Console.WriteLine();
for (int i = 1; i <= bil; i++)
{
for (int j = 1; j <= 1; j++)
{
a = a + i;
Console.WriteLine(" {0} {1}", i, a);
}
}
Console.ReadKey();

}
2.. Buatlah program dengan menggunakan conditional looping!
//RIDHATUR ROHMAT

using System;

using System.Collections.Generic;

using System.Linq;
using System.Text;

using System.Threading.Tasks;

namespace Tugas_2

class Program
{

static void Main(string[] args)

int a=0,b,d,e=0,f,i=0,c=0,j;

Console.Write(" Masukkan Angka Kurang Dari 10 : "); int juml = Convert.ToInt32(Console.ReadLine());


Console.WriteLine();

do

j = i + 1;

while (j == 1)

for (a = 1; a <= juml; a++)

Console.Write("\t" + a);
}

Console.Write("\n\n");

break;

while (j == 2)

for (c = juml + 1; c <= (juml + (juml - 2)); c++)

for (b = 1; b <= juml; b++)

Console.Write("\t");

Console.Write(c);

Console.Write("\n\n");

break;

while (j == 3)

for (d = (c + (juml - 1)); d >= c; d--)

Console.Write("\t" + d);

break;

while (j == 4)

for (e = juml + c; e <= (juml + c + (juml - 3)); e++)

Console.Write("\n\n\t");

Console.Write(e);

}
Console.WriteLine("\n");
break;

while (j == 5)

for (f = e; f < (e + juml); f++)

Console.Write("\t" + f);

} break;

i++;

} while (i <= 5);

Console.ReadKey();

}
3.Buatlah program tangga naik menggunakan struktur pengulangan sehingga hasil output:
//RIDHATUR ROHMAT

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
using System.Threading.Tasks;

namespace Tugas_3
{

class Program
{

static void Main(string[] args)


{

Console.Write("Input : ");

int tinggi = Convert.ToInt16(Console.ReadLine()); for (int i = 1; i <= tinggi; i++)


{

for (int j = 1; j <= i; j++)


{

Console.Write(j + " ");

Console.WriteLine();

Console.ReadKey();

}
}
}

4. Masukan tiap program diatas kedalam suatu menu pilihan!


//RIDHATUR ROHMAT

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;
using System.Threading.Tasks;

namespace Tugas_4
{

class Program

static void Main(string[] args)

int pilih;

char ulang;

menu:

Console.WriteLine("\n No \t Program\n");

Console.WriteLine(" 1 \t Membalik Kata");

Console.WriteLine(" 2 \t mengurutkan bilangan total");

Console.WriteLine(" 3 \t Membuat pola angka 5 dengan kelipatan

angka");

Console.WriteLine(" 4 \t membuat segitiga siku-siku dengan angka

\n");

Console.Write("Masukkan Pilihan Anda : (1/2/3/4) ? ... "); pilih=Convert.ToInt16(Console.ReadLine());


Console.Clear();

switch (pilih)
{

case 1:

string[] proses;

string kata;

Console.Write("\n Masukkan Kata : ");

kata = Convert.ToString(Console.ReadLine());

proses = new string[kata.Length];

for (int i = 0; i < kata.Length; i++)

proses[i] = kata.Substring(kata.Length - (i + 1), 1);

Console.Write("\n Hasil Kebalikan Dari Kata " + kata + "

adalah ");

for (int i = 0; i < (kata.Length); i++)

Console.Write(proses[i]);

Console.Write("\n\n Apakah Ingin Kembali Ke Menu ??? (y/t)...

");

ulang = Convert.ToChar(Console.ReadLine());

if (ulang == 'y')

Console.Clear();

goto menu;

else

break;

case 2:

int bil, a = 0;
Console.Write("\n Masukkan Bilangan : ");

bil = Convert.ToInt32(Console.ReadLine());

Console.WriteLine();

for (int i = 1; i <= bil; i++)

for (int j = 1; j <= 1; j++)

a = a + i;

Console.WriteLine("

{0}

{1}", i, a);

Console.Write("\n\n Apakah Ingin Kembali Ke Menu ??? (y/t)...

");

ulang = Convert.ToChar(Console.ReadLine());

if (ulang == 'y')

Console.Clear();

goto menu;

else

break;

case 3:

int a = 0, b, d, e = 0, f, i = 0, c = 0, j;

Console.Write(" Masukkan Angka Kurang Dari 10 : "); int juml = Convert.ToInt32(Console.ReadLine());


Console.WriteLine();
do

j = i + 1;

while (j == 1)

for (a = 1; a <= juml; a++)

Console.Write("\t" + a);

Console.Write("\n\n");

break;

while (j == 2)

for (c = juml + 1; c <= (juml + (juml - 2));


c++)

for (b = 1; b <= juml; b++)

Console.Write("\t");

Console.Write(c);

Console.Write("\n\n");

break;

while (j == 3)

for (d = (c + (juml - 1)); d >= c; d--)

Console.Write("\t" + d);
}

break;

while (j == 4)

for (e = juml + c; e <= (juml + c + (juml -

3)); e++)

Console.Write("\n\n\t");

Console.Write(e);

Console.WriteLine("\n");

break;

while (j == 5)

for (f = e; f < (e + juml); f++)

Console.Write("\t" + f);

} break;

i++;

} while (i <= 5);

Console.Write("\n\n Apakah Ingin Kembali Ke Menu ???


(y/t)... ");

ulang = Convert.ToChar(Console.ReadLine());

if (ulang == 'y')

Console.Clear();

goto menu;

}
else

break;

case 4:

Console.Write("\n Masukkan Tinggi Segitiga : "); int tinggi = Convert.ToInt16(Console.ReadLine()); for


(int i = 1; i <= tinggi; i++) {

for (int j = 1; j <= i; j++)

Console.Write(j + " ");

Console.WriteLine();

Console.Write(" Apakah Ingin Kembali Ke Menu ??? (y/t)... "); ulang = Convert.ToChar(Console.ReadLine());

if (ulang == 'y')

Console.Clear();

goto menu;

else

break;

default:

Console.WriteLine(" Nomer yang anda masukkan tidak

tersedia\n");

Console.WriteLine(" Tekan Enter untuk Kembali ke menu");

Console.ReadKey();

Console.Clear();

goto menu;

Console.ReadKey();
}

}
}

You might also like