1.
Konversi Kecepatan
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no1
{
class Program
{
static void Main(string[] args)
{
string nama;
int Berat, Tinggi;
float BMI, TinggiMeter;
Console.Write("\tNama = ");
nama = Console.ReadLine();
Console.Write("\tBerat
badan <kg> = ");
Berat = Convert.ToInt32(Console.ReadLine());
Console.Write("\tMasukkan
Tinggi <cm> = ");
Tinggi = Convert.ToInt32(Console.ReadLine());
TinggiMeter = (float)Tinggi / 100;
BMI = (float)Berat / (TinggiMeter *
TinggiMeter);
Console.WriteLine();
Console.Write("Anda
{0} memiliki kondisi berat badan\"", nama);
if (BMI > 40)
Console.WriteLine("Obesitas");
else if (BMI >
27.6)
Console.WriteLine("Kegemukan");
else if (BMI > 23)
Console.WriteLine("Gemuk");
else if (BMI >
18.5)
Console.WriteLine("Ideal");
else if (BMI > 15)
Console.WriteLine("Kurus");
else if (BMI <
14.9)
Console.WriteLine("Indikasi Busung lapar");
Console.ReadKey();
}
}
}
Hasil
2.
Penghitung
Total Pembelian
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\t\t
Aplikasi Console Program Pembelian Barang");
Console.WriteLine("\t\t===========================================\n\n\n");
//Looping input jumlah barang dengan menggunakan kondisi do
while
int jml;
do
{
Console.Write("Masukkan jumlah barang [1..5] : ");
jml = int.Parse(Console.ReadLine());
} while (jml <= 1 || jml > 5);
//Looping dengan menggunakan kombinasi Array. Akan mencetak
inputan nama barang dan harga barang
string[] nama = new string[jml];
int[]
harga = new int[jml];
int total = 0;
int bayar, kembali;
for (int i = 0; i
< jml; i++)
{
do
{
Console.Write("\nMasukkan nama barang Ke-" + (i + 1) + " [3..10 karakter] : ");
nama[i] = Console.ReadLine();
} while (nama[i].Length <= 3 ||
nama[i].Length >= 10);
do
{
Console.Write("Masukkan harga barang Ke-" + (i + 1) + " [1000...10000] : ");
harga[i] = int.Parse(Console.ReadLine());
//kondisi bahwa user harus input harga barang
antara 1000-10000
} while (harga[i] <= 1000 || harga[i]
>= 10000);
}
//Menampilkan list harga dan barang yang dibeli
Console.WriteLine("\n\nBarang
yang dibeli");
Console.WriteLine("=============================");
for (int i = 0; i
< jml; i++)
{
Console.WriteLine((i
+ 1) + ". " + nama[i] + " "
+ harga[i]);
}
foreach (int i in harga)
{
total += i;
}
//Menampilkan total harga
Console.WriteLine("=============================");
Console.WriteLine("Total " + total);
do
{
Console.Write("\n\nUang Bayar : ");
bayar = int.Parse(Console.ReadLine());
//Logika untuk mendapatkan uang kembali dari
uang bayar yang di input oleh user
kembali = bayar - total;
//Kondisi jika input uang bayar lebih kecil
dari total harga
if (bayar < total)
{
Console.WriteLine("Maaf, uang anda kurang !!");
Console.WriteLine("-------------------------");
}
//Jika kondisi bernilai benar (input uang
bayar lebih besar dari total harga)
else
{
Console.WriteLine("\nUang kembalian anda Rp. " + kembali +
",00");
}
/*statement dimana uang bayar akan selalu di
looping bila input uang bayar lebih dari total harga
dan akan mencetak kode;
Console.Write("\n\nUang Bayar : ");
bayar =
int.Parse(Console.ReadLine());
pada console*/
} while (bayar < total);
//Mencetak ucapan terima kasih
Console.WriteLine("\n\n\t\t^_^
Terimakasih telah berbelanja di toko kami ^_^");
//Menahan 1 kali enter sebelum console tertutup
Console.ReadLine();
}
}
}
Hasil
3.
Menentukan Jenis Segitiga
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no3
{
class Program
{
static void Main(string[] args)
{
int a, b, c;
Console.Write("Input
panjang Sisi-1 = ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Input
panjang Sisi-2 = ");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Input
panjang sisi-3 = ");
c = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
if (a == b && b == c)
{
Console.WriteLine("Hasil: \"Segitiga Sama Sisi\"");
}
else if (a == b
&& b != c || b == c && c != a || a == c && c != b)
{
Console.WriteLine("Hasil: \"Segitiga Sama kaki\"");
}
else if ((a * a) ==
((b * b) + (c * c)) || (b * b) == ((a * a) + (c * c)) || (c * c) == ((b * b) +
(a * a)))
{
Console.WriteLine("Hasil: \"Segitiga Phytagoras\"");
}
else
{
Console.WriteLine("Hasil: \"Segitiga Sembarang\"");
}
Console.ReadKey();
}
}
}
Hasil
4.
Faktor Perkalian
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no4
{
class Program
{
static void Main(string[] args)
{
int bilangan;
Console.Write("Input
Suatu Bilangan = ");
bilangan = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.Write("Faktor
Perkalian dari {0} adalah = ", bilangan);
for (int i = 2; i
< bilangan; i++)
{
if (bilangan % i == 0)
{
Console.Write(i + " ");
}
}
Console.ReadKey();
}
}
}
Hasil
5.
Menghitung Barisan dan Tampilan
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hitung
3 + 6 + 9 +...+ N");
Console.WriteLine("========================");
Console.WriteLine();
int hasil = 0;
int a = 3;
int b = 0;
int temp = 0;
int bilangan;
Console.Write("Jumlah
Bilangan (min.1) = ");
bilangan = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i
<= bilangan; i++)
{
b += a;
temp += b;
hasil = temp;
}
Console.WriteLine();
Console.WriteLine("Hasil
= {0} ", hasil);
Console.ReadKey();
}
}
}
Hasil
6.
Menghitung
Pengurangan
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no6
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hitung
2 - 4 + 6 - 8 -...-/ N");
Console.WriteLine("========================");
Console.WriteLine();
int hasil = 0;
int a = 0;
int b = 1;
int temp = 1;
int bilangan;
Console.Write("Jumlah
Bilangan (min.1) = ");
bilangan = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i
<= bilangan; i++)
{
b += a;
temp += b;
hasil = temp;
}
Console.WriteLine();
Console.WriteLine("Hasil
= {0} ", hasil);
Console.ReadKey();
}
}
}
Hasil
7.
Menghitung
Barisan Bagi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no7
{
class Program
{
static void Main(string[] args)
{
int n; float hasil =
0;
int a = 1, b = 2;
Console.WriteLine("Hitung
(1/2) - (2/3) + (3/4) - (4/5)+...+- N");
Console.WriteLine("============================================");
Console.WriteLine();
Console.Write("jumlah
bilangan (min.1) = ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
for (int i = 1; i
<= n; i++)
{
float c = (float)a
/ b;
if (i % 2 == 0)
hasil -= c;
else
hasil += c;
a += 1; b += 1;
}
Console.WriteLine("Hasil=
" + hasil);
Console.ReadKey();
}
}
}
Hasil
8.
Perulangan Karakter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no8
{
class Program
{
static void Main(string[] args)
{
char a;
int n;
Console.Write("Input
1 karakter = ");
a = Convert.ToChar(Console.ReadLine());
Console.Write("Jumlah
Tingkatan (min.1) =");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
for (int i = n; i
> 0; i--)
{
for (int
j = i; j > 0; j--)
Console.Write(a);
Console.WriteLine();
}
for (int i = 1; i
<= n; i++)
{
for (int
j = i; j > 0; j--)
Console.Write(a);
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Hasil
9.
Menghitung Barisan Karakter Bermotif
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace no9
{
class Program
{
static void Main(string[] args)
{
string A;
int n, i, j, k;
Console.Write("Input
1 karakter\t=");
A = Console.ReadLine();
Console.Write("jumlah
tingkatan <min.1>=");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n");
for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
Console.Write("{0}", A);
}
for (k = i; k < n; k++)
{
Console.Write(" ");
}
for (k = i; k < n; k++)
{
Console.Write(" ");
}
//bintang kedua
for (j = 1; j <= i; j++)
{
Console.Write("{0}", A);
}
Console.Write("\n");
}
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write("{0}", A);
}
for (k = i; k < n; k++)
{
Console.Write(" ");
}
for (k = i; k < n; k++)
{
Console.Write(" ");
}
for (j = 1; j <= i; j++)
{
Console.Write("{0}", A);
}
Console.Write("\n");
}
Console.ReadKey();
}
}
}
Hasil
0 comments:
Post a Comment