Inspirasi
Jumat, 04 Maret 2011
BAHASA C#
PROGRAM SEDERHANA
HelloWorld C#
using System;
namespace HelloWorld_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
//Menampilkan Hello World
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\t\t\t\t Hello World ");
Console.ReadLine();
}
}
}
Variabel_Konstanta_dan_Tipe_data C#
using System;
namespace Variabel_Konstanta_dan_Tipe_data_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
//Deklarasi tipe data integer dengan variabel a b c
int a,b,c;
//Deklarasi Konstanta dari variabel b, yaitu 2
b = 2;
Console.Write("Input Angka : ");
//ganti tipe data dari string ke integer
a = Convert.ToInt32(Console.ReadLine());
c = a % b;
if(c==0)
{
Console.WriteLine("Angka {0} adalah bilangan genap",a);
}
if(c!=0)
{
Console.WriteLine("Angka {0} adalah bilangan ganjil",a);
}
Console.ReadLine();
}
}
}
Operator C#
using System;
namespace Operator_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
string ulang;
do
{
Console.WriteLine(" Program Kalkulator");
Console.WriteLine("\n 1. Penjumlahan \n 2. Pngurangan \n 3. Perkalian \n 4. Pembagian");
Console.Write("\n Masukkan Pilihan Anda:");
int pilihan = Convert.ToInt32(Console.ReadLine());
if (pilihan == 1)
{
Console.WriteLine("\n Penjumlahan");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama + kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
if (pilihan == 2)
{
Console.WriteLine("\n Pengurangan");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama - kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
if (pilihan == 3)
{
Console.WriteLine("\n Perkalian");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama * kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
if (pilihan == 4)
{
Console.WriteLine("\n Pembagian");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama / kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
Console.WriteLine(" Maaf Kode Salah !");
}
}
}
}
Console.Write(" Ingin Mengulang [y/t] : ");
ulang = Console.ReadLine();
}while (ulang == "y");
Console.WriteLine("\n Terima Kasih Telah Menggunakan Program Ini");
Console.ReadLine();
}
}
}
If C#
using System;
namespace If_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("\n\t\t\t PT.SUKA-SUKA");
Console.WriteLine("\n\t\t Program Gaji Karyawan per hari");
Console.Write("\n\n\n\t\t\tMasukkan Jam Kerja : ");
//Input jam
int jam = Convert.ToInt32(Console.ReadLine());
//Menentukan Gaji
if (jam > 15 && jam <= 24)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 150.000");
}
else
{
if (jam > 10 && jam <=15)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 100.000");
}
else
{
if (jam >5 && jam <=10)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 50.000");
}
else
{
if (jam >0 && jam <=5)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 20.000");
}
else
{
Console.WriteLine("\n\t\t\tANDA MELEBIHI JAM NORMAL");
}
}
}
}
Console.ReadLine();
}
}
}
Loop C#
using System;
namespace Loop_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
int a,b;
long c;
c = 1;
Console.WriteLine("Program menghitung bilangan faktorial\n");
Console.Write("Input Angka : ");
a = Convert.ToInt32(Console.ReadLine());
for(b=1;b<=a;b++)
{
c = c * b;
}
Console.WriteLine("\n\nNilai Faktorial Dari {0} adalah {1}",a,c);
Console.ReadLine();
}
}
}
Array C#
using System;
namespace Array_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
int[] nopeserta={1001,1002,1003,1004,1005};
string[] nama={"Fauzan H","Guruh M.P","Hilma A","Imam","Lia"};
Console.WriteLine("\n\t\t\tNo.Peserta||Nama Peserta");
Console.WriteLine("\n\t\t\t----------||------------");
int i=0;
for (i=0;i<5;i++)
{
Console.WriteLine("\n\t\t\t {0} || {1}",nopeserta[i],nama[i]);
}
Console.ReadLine();
}
}
}
membaca_dan_menulis C#
using System;
namespace membaca_dan_menulis_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
string nama;
Console.Write("\n\n\t Input Nama Orang Tua Anda : ");
nama = Console.ReadLine();
Console.WriteLine("\n\n\t Nama Orang Tua Anda : {0}",nama);
Console.ReadLine();
}
}
}
Exceptional_Handing C#
using System;
namespace Exceptional_Handing_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
int a,b,c;
try
{
Console.Write("Input Nilai Pertama: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Input Nilai Kedua: ");
b = Convert.ToInt32(Console.ReadLine());
c = a * b;
Console.WriteLine("{0} * {1} = {2}",a,b,c);
Console.ReadLine();
}
catch
{
Console.WriteLine("Maaf, Anda Salah Input");
Console.ReadLine();
}
}
}
}
Selisih_Waktu C#
using System;
namespace Selisih_Waktu_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
///deklarasi
int j1,m1,d1,j2,m2,d2,j3,m3,d3;
Console.Write("Jam Mulai : ");
j1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Menit Mulai : ");
m1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Detik Mulai : ");
d1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Jam Akhir : ");
j2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Menit Akhir : ");
m2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Detik Akhir : ");
d2 = Convert.ToInt32(Console.ReadLine());
if (j1 <24 && j2 < 24 && m1<60 && m2 <60 && d1 <60 && d2 < 60)
{
if (d2 < d1)
{
d2=d2+60;
m2=m2-1;
d3=d2-d1;
if (m2 < m1 )
{
m2=m2 +60;
j2=j2-1;
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
else
{
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
}
else
{
d3=d2-d1;
if (m2 < m1 )
{
m2=m2 +60;
j2=j2-1;
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
else
{
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
}
}
else
{
Console.WriteLine("Error!!!");
}
Console.ReadLine();
}
}
}
Faktorial C#
using System;
namespace Faktorial_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
///deklarasi
int n,fak,k;
Console.Write("Input bilangan : ");
n = Convert.ToInt32(Console.ReadLine());
k=1;
fak=1;
if (n==0)
{
fak = 1;
}
else
{
for(k=1;k<=n;k++)
{
fak=fak*k;
}
}
Console.WriteLine("Hasil adalah {0}",fak);
Console.ReadLine();
}
}
}
Perbandingan_Angka C#
using System;
namespace Perbandingan_Angka_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Console.Write("\n A = ");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write(" B = ");
int kedua = Convert.ToInt32(Console.ReadLine());
Console.Write(" C = ");
int ketiga = Convert.ToInt32(Console.ReadLine());
if (pertama > kedua && pertama > ketiga)
{
Console.WriteLine(" Bilangan terbesar adalah {0}",pertama);
}
else
{
if (kedua > pertama && kedua > ketiga)
{
Console.WriteLine(" Bilangan terbesar adalah {0}",kedua);
}
else
{
Console.WriteLine(" Bilangan terbesar adalah {0}",ketiga);
}
}
Console.ReadLine();
}
}
}
kalkulator C#
using System;
namespace kalkulator_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
char opr;
float pertama,kedua,jumlah;
Console.Write(" Angka 1 : ");
pertama = Convert.ToInt32(Console.ReadLine());
Console.Write(" Operator (+, -, *, /) : ");
opr = Convert.ToChar(Console.ReadLine());
Console.Write(" Angka 2 : ");
kedua = Convert.ToInt32(Console.ReadLine());
switch(opr)
{
case '+' : jumlah = pertama + kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
case '-' : jumlah = pertama - kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
case '*' : jumlah = pertama * kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
case '/' : jumlah = pertama / kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
}
Console.ReadLine();
}
}
}
DIBERIKAN TANGGAL : 2 Maret 2011
DIKUMPULKAN TANGGAL : 4 Maret 2011
HelloWorld C#
using System;
namespace HelloWorld_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
//Menampilkan Hello World
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\t\t\t\t Hello World ");
Console.ReadLine();
}
}
}
Variabel_Konstanta_dan_Tipe_data C#
using System;
namespace Variabel_Konstanta_dan_Tipe_data_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
//Deklarasi tipe data integer dengan variabel a b c
int a,b,c;
//Deklarasi Konstanta dari variabel b, yaitu 2
b = 2;
Console.Write("Input Angka : ");
//ganti tipe data dari string ke integer
a = Convert.ToInt32(Console.ReadLine());
c = a % b;
if(c==0)
{
Console.WriteLine("Angka {0} adalah bilangan genap",a);
}
if(c!=0)
{
Console.WriteLine("Angka {0} adalah bilangan ganjil",a);
}
Console.ReadLine();
}
}
}
Operator C#
using System;
namespace Operator_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
string ulang;
do
{
Console.WriteLine(" Program Kalkulator");
Console.WriteLine("\n 1. Penjumlahan \n 2. Pngurangan \n 3. Perkalian \n 4. Pembagian");
Console.Write("\n Masukkan Pilihan Anda:");
int pilihan = Convert.ToInt32(Console.ReadLine());
if (pilihan == 1)
{
Console.WriteLine("\n Penjumlahan");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama + kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
if (pilihan == 2)
{
Console.WriteLine("\n Pengurangan");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama - kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
if (pilihan == 3)
{
Console.WriteLine("\n Perkalian");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama * kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
if (pilihan == 4)
{
Console.WriteLine("\n Pembagian");
Console.Write("\n Iput Bilangan Pertama:");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write("\n Input Bilangan Kedua :");
int kedua =Convert.ToInt32(Console.ReadLine());
int hasil = pertama / kedua;
Console.WriteLine("\n Hasil adalah {0}",hasil);
}
else
{
Console.WriteLine(" Maaf Kode Salah !");
}
}
}
}
Console.Write(" Ingin Mengulang [y/t] : ");
ulang = Console.ReadLine();
}while (ulang == "y");
Console.WriteLine("\n Terima Kasih Telah Menggunakan Program Ini");
Console.ReadLine();
}
}
}
If C#
using System;
namespace If_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("\n\t\t\t PT.SUKA-SUKA");
Console.WriteLine("\n\t\t Program Gaji Karyawan per hari");
Console.Write("\n\n\n\t\t\tMasukkan Jam Kerja : ");
//Input jam
int jam = Convert.ToInt32(Console.ReadLine());
//Menentukan Gaji
if (jam > 15 && jam <= 24)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 150.000");
}
else
{
if (jam > 10 && jam <=15)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 100.000");
}
else
{
if (jam >5 && jam <=10)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 50.000");
}
else
{
if (jam >0 && jam <=5)
{
Console.WriteLine("\n\t\t\tGaji : Rp. 20.000");
}
else
{
Console.WriteLine("\n\t\t\tANDA MELEBIHI JAM NORMAL");
}
}
}
}
Console.ReadLine();
}
}
}
Loop C#
using System;
namespace Loop_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
int a,b;
long c;
c = 1;
Console.WriteLine("Program menghitung bilangan faktorial\n");
Console.Write("Input Angka : ");
a = Convert.ToInt32(Console.ReadLine());
for(b=1;b<=a;b++)
{
c = c * b;
}
Console.WriteLine("\n\nNilai Faktorial Dari {0} adalah {1}",a,c);
Console.ReadLine();
}
}
}
Array C#
using System;
namespace Array_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
int[] nopeserta={1001,1002,1003,1004,1005};
string[] nama={"Fauzan H","Guruh M.P","Hilma A","Imam","Lia"};
Console.WriteLine("\n\t\t\tNo.Peserta||Nama Peserta");
Console.WriteLine("\n\t\t\t----------||------------");
int i=0;
for (i=0;i<5;i++)
{
Console.WriteLine("\n\t\t\t {0} || {1}",nopeserta[i],nama[i]);
}
Console.ReadLine();
}
}
}
membaca_dan_menulis C#
using System;
namespace membaca_dan_menulis_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
string nama;
Console.Write("\n\n\t Input Nama Orang Tua Anda : ");
nama = Console.ReadLine();
Console.WriteLine("\n\n\t Nama Orang Tua Anda : {0}",nama);
Console.ReadLine();
}
}
}
Exceptional_Handing C#
using System;
namespace Exceptional_Handing_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
int a,b,c;
try
{
Console.Write("Input Nilai Pertama: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Input Nilai Kedua: ");
b = Convert.ToInt32(Console.ReadLine());
c = a * b;
Console.WriteLine("{0} * {1} = {2}",a,b,c);
Console.ReadLine();
}
catch
{
Console.WriteLine("Maaf, Anda Salah Input");
Console.ReadLine();
}
}
}
}
Selisih_Waktu C#
using System;
namespace Selisih_Waktu_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
///deklarasi
int j1,m1,d1,j2,m2,d2,j3,m3,d3;
Console.Write("Jam Mulai : ");
j1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Menit Mulai : ");
m1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Detik Mulai : ");
d1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Jam Akhir : ");
j2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Menit Akhir : ");
m2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Detik Akhir : ");
d2 = Convert.ToInt32(Console.ReadLine());
if (j1 <24 && j2 < 24 && m1<60 && m2 <60 && d1 <60 && d2 < 60)
{
if (d2 < d1)
{
d2=d2+60;
m2=m2-1;
d3=d2-d1;
if (m2 < m1 )
{
m2=m2 +60;
j2=j2-1;
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
else
{
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
}
else
{
d3=d2-d1;
if (m2 < m1 )
{
m2=m2 +60;
j2=j2-1;
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
else
{
m3=m2-m1;
j3=j2-j1;
Console.WriteLine("Lama Bicara : {0} jam {1} menit {2} Detik ",j3,m3,d3);
}
}
}
else
{
Console.WriteLine("Error!!!");
}
Console.ReadLine();
}
}
}
Faktorial C#
using System;
namespace Faktorial_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
///deklarasi
int n,fak,k;
Console.Write("Input bilangan : ");
n = Convert.ToInt32(Console.ReadLine());
k=1;
fak=1;
if (n==0)
{
fak = 1;
}
else
{
for(k=1;k<=n;k++)
{
fak=fak*k;
}
}
Console.WriteLine("Hasil adalah {0}",fak);
Console.ReadLine();
}
}
}
Perbandingan_Angka C#
using System;
namespace Perbandingan_Angka_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Console.Write("\n A = ");
int pertama = Convert.ToInt32(Console.ReadLine());
Console.Write(" B = ");
int kedua = Convert.ToInt32(Console.ReadLine());
Console.Write(" C = ");
int ketiga = Convert.ToInt32(Console.ReadLine());
if (pertama > kedua && pertama > ketiga)
{
Console.WriteLine(" Bilangan terbesar adalah {0}",pertama);
}
else
{
if (kedua > pertama && kedua > ketiga)
{
Console.WriteLine(" Bilangan terbesar adalah {0}",kedua);
}
else
{
Console.WriteLine(" Bilangan terbesar adalah {0}",ketiga);
}
}
Console.ReadLine();
}
}
}
kalkulator C#
using System;
namespace kalkulator_0320100014
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
char opr;
float pertama,kedua,jumlah;
Console.Write(" Angka 1 : ");
pertama = Convert.ToInt32(Console.ReadLine());
Console.Write(" Operator (+, -, *, /) : ");
opr = Convert.ToChar(Console.ReadLine());
Console.Write(" Angka 2 : ");
kedua = Convert.ToInt32(Console.ReadLine());
switch(opr)
{
case '+' : jumlah = pertama + kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
case '-' : jumlah = pertama - kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
case '*' : jumlah = pertama * kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
case '/' : jumlah = pertama / kedua;
Console.WriteLine(" Jumlah adalah {0}",jumlah);
break;
}
Console.ReadLine();
}
}
}
DIBERIKAN TANGGAL : 2 Maret 2011
DIKUMPULKAN TANGGAL : 4 Maret 2011
Langganan:
Komentar (Atom)