This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Sunday, March 6, 2011

SELISIH WAKTU


using System;

namespace Selisilh_waktu_0320100017
{
class Class1
{
public struct jam
{
public int hh;
public int mm;
public int ss;
}
static void Main(string[] args)
{
jam w1;
jam w2;
jam w3;
Console.Write("Jam awal percakapan : ");
w1.hh = Convert.ToInt32(Console.ReadLine());
Console.Write("Menit awal percakapan : ");
w1.mm = Convert.ToInt32(Console.ReadLine());
Console.Write("Detik awal percakapan : ");
w1.ss = Convert.ToInt32(Console.ReadLine());
Console.Write("Jam akhir percakapan : ");
w2.hh = Convert.ToInt32(Console.ReadLine());
Console.Write("Menit akhir percakapan : ");
w2.mm = Convert.ToInt32(Console.ReadLine());
Console.Write("Detik awal percakapan : ");
w2.ss = Convert.ToInt32(Console.ReadLine());
w3.mm = 0;
w3.ss = 0;
if(w2.ss>=w1.ss)
{
w3.ss=w2.ss-w1.ss;
if(w2.mm>=w1.mm)
{
w3.mm=w2.mm-w1.mm;
w3.hh=w2.hh-w1.hh;
Console.WriteLine("{0},{1},{2}",w3.hh,w3.mm,w3.ss);
}
if(w2.mm<w1.mm)
{
w3.mm=(w2.mm+60)-w1.mm;
w2.hh=w2.hh-1;
w3.hh=w2.hh-w1.hh;
Console.WriteLine("{0},{1},{2}",w3.hh,w3.mm,w3.ss);
}

}
if(w2.ss<w1.ss)
{
w3.ss=(w2.ss+60)-w1.ss;
w2.mm=w2.mm-1;
if(w2.mm>=w1.mm)
{
w3.mm=w2.mm-w1.mm;
w3.hh=w2.hh-w1.hh;
Console.WriteLine("{0},{1},{2}",w3.hh,w3.mm,w3.ss);
}
if(w2.mm<w1.mm)
{
w3.mm=(w2.mm+60)-w1.mm;
w2.hh=w2.hh-1;
w3.hh=w2.hh-w1.hh;
Console.WriteLine("{0},{1},{2}",w3.hh,w3.mm,w3.ss);
}
}
Console.ReadLine();
}
}
}

FAKTORIAL


using System;

namespace Faktorial_017
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
int n, fak, k,i,l;
Console.Write("Masukkan Bilangan : ");
n=Convert.ToInt32(Console.ReadLine());
if(n==0)
{
Console.WriteLine("Faktorial : 1");
Console.ReadLine();
}
else
{
fak=1;
for(i=n;i>=1;i--)
{
l=fak*i;
fak=l;
}
Console.WriteLine("Nilai faktorial adalah : {0}",fak);
Console.ReadLine();
}
}
}
}

BILANGAN TERBESAR


using System;

namespace Perbandingan_Angka_017
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
int a,b,c;
Console.Write("A=? ");
a=Convert.ToInt32(Console.ReadLine());
Console.Write("B=? ");
b=Convert.ToInt32(Console.ReadLine());
Console.Write("C=? ");
c=Convert.ToInt32(Console.ReadLine());
if(a>b)
{
if(a>c)
{
Console.WriteLine("Bilangan terbesar adalah {0}",a);
}
}
if(c>b)
{
if(c>a)
{
Console.WriteLine("Bilangan terbesar adalah {0}",c);
}
}
if(b>a)
{
if(b>c)
{
Console.WriteLine("Bilangan terbesar adalah {0}",b);
}
}
if(a==b && a==c)
{
Console.WriteLine("Semua bilangan sama besar");
}
if(a==b && a>c)
{
Console.WriteLine("Bilangan terbesar ada dua dg angka {0}",a);
}
if(b==c && b>a)
{
Console.WriteLine("Bilangan terbesar ada dua dg angka {0}",b);
}
if(a==c && a>b)
{
Console.WriteLine("Bilangan terbesar ada dua dg angka {0}",a);
}
Console.ReadLine();


}
}
}

KALKULATOR


using System;

namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
double a,b,d;
string c;
try
{
Console.Write("Angka 1 : ");
a=Convert.ToInt32(Console.ReadLine());
Console.Write("+, -,* ,/ : ");
c=Convert.ToString(Console.ReadLine());
Console.Write("Angka 2 : ");
b=Convert.ToInt32(Console.ReadLine());
switch(c)
{
case "+" : d=a+b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
case "-" : d=a-b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
case "*" : d=a*b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
case "/" : d=a/b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
default  :Console.WriteLine("Tanda yang anda masukkan salah");
break;
}
}
catch
{
Console.WriteLine("Maaf Inputan Anda salah, silahkan coba lagi");
Console.ReadLine();
}
}
}
}

Saturday, March 5, 2011

HELLO WORLD


using System;

namespace hello_world_0320100017
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Hello world");//tampilan
Console.ReadLine();
}
}
}

VARIABEL, KONSTANTA dan TIPE DATA


using System;

namespace varkonsttipedata
{
class latihan2
{
[STAThread]
static void Main(string[] args)
{
int x,y,z;//tipe data integer dg variabel x,y,z
y=2;//konstanta dari variabel y adalah 2
Console.WriteLine("\t\tKONSTANTA, VARIABEL dan TIPE DATA");
Console.WriteLine("Masukkan angka : ");
x=Convert.ToInt32(Console.ReadLine());
z=x % y;
if(z==0)
{
Console.WriteLine("Bilangan {0} adalah bilangan genap",x);
Console.ReadLine();
}
else
{
Console.WriteLine("Bilangan {0} adalah bilangan ganjil",x);
Console.ReadLine();
}

}
}
}

OPERATOR


using System;

namespace aku
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
int x,y,z;
Console.WriteLine("\t\t\t\tOPERATOR\n");
Console.Write("\t\tbilangan pertama : ");
x=Convert.ToInt32(Console.ReadLine());
Console.Write("\t\tbilangan kedua : ");
y=Convert.ToInt32(Console.ReadLine());
z=x+y;
Console.WriteLine("\t\tHasil penjumlahan adalah : {0}",z);
Console.ReadLine();

}
}
}

IF


using System;

namespace ConsoleApplication1
{
class coba
{
[STAThread]
static void Main(string[] args)
{
int a,b;
Console.WriteLine("\t\t\t\tif");
Console.WriteLine("\t\t==============================");
Console.Write("Masukkan bilangan pertama : ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Masukkan bilangan kedua   : ");
b = Convert.ToInt32(Console.ReadLine());
if(a>b)//if syarat
{
Console.WriteLine("\nBilangan terbesar adalah : {0}",a);
Console.ReadLine();
}
if(a<b)//if syarat
{
Console.WriteLine("\nBilangan terbesar adalah : {0}",b);
Console.ReadLine();
}

}
}
}

LOOP


using System;

namespace loop
{
class loop
{
[STAThread]
static void Main(string[] args)
{
int a,b,i;
string c,d,z;
Console.WriteLine("\t\t\t\t    LOOP");
Console.WriteLine("\t\t\t\t==============\n\n");
Console.WriteLine("\t\t\t\tData Mahasiswa");
Console.WriteLine("\t\t\t\t==============");
Console.Write("\tMasukkan jumlah Mahasiswa yg akan di input datanya : ");
a=Convert.ToInt32(Console.ReadLine());
do//pengulangan apabila while memenuhi syarat
{
for (i=1;i<=a;i++)//loop pake for
{
Console.WriteLine("\n");
Console.WriteLine("\t\t\tData Mahasiswa ke {0}",i);
for(b=1;b<=i;b++);
{
Console.Write("\t\t\tNama Mahasiswa : ");
c=Console.ReadLine();
Console.WriteLine("\t\t\tNama Mahasiswa adalah {0}",c);
Console.Write("\t\t\tTtl : ");
d=Console.ReadLine();
Console.WriteLine("\t\t\tTanggal Lahirnya {0}",d);

}
}
Console.WriteLine("\t\t\tApakah Anda ingin mengulang ?");
z=Console.ReadLine();
}
while (z=="y"||z=="Y");
Console.WriteLine("\t\t\tThank u for using this program");
Console.ReadLine();
}
}
}

ARRAY

using System; namespace array { class latihan6 { [STAThread] static void Main(string[] args) { int a,b,d; string [] c= new string [10]; string [] e= new string [10]; Console.WriteLine("\t\t\t\tARRAY PROGRAM"); Console.WriteLine("\t\t\t\t============="); Console.Write("\nJumlah Barang yang akan di input data: "); a=Convert.ToInt32(Console.ReadLine()); for (b=1;b<=a;b++) { Console.WriteLine("\tBarang ke {0}",b); Console.Write("\tNama Barang : "); c[b]=Console.ReadLine();//ex :pakai arRay Console.Write("\tJumlah : "); e[b]=Console.ReadLine();//ex :pakai array } for (b=1;b<=a;b++) { Console.WriteLine("\n"); Console.WriteLine("\t=================="); Console.WriteLine("\tBarang ke {0}",b); Console.WriteLine("\tNama Barang :{0}",c[b]); Console.WriteLine("\tJumlah :{0}",e[b]); } Console.ReadLine(); } } }

MEMBACA dan MENULIS ke LAYAR


using System;

namespace membaca_n_menulis_ke_layar_0320100017
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string a,b,c,d,e,f;
Console.WriteLine("\t\t*****My Biodata*****");
Console.WriteLine("\t\t====================");
Console.Write("Nama Anda : ");
a=Convert.ToString(Console.ReadLine());
Console.Write("TTL : ");
b=Convert.ToString(Console.ReadLine());
Console.Write("Alamat : ");
c=Convert.ToString(Console.ReadLine());
Console.Write("Agama : ");
d=Convert.ToString(Console.ReadLine());
Console.Write("Hobby : ");
e=Convert.ToString(Console.ReadLine());
Console.Write("Prinsip hidup : ");
f=Convert.ToString(Console.ReadLine());
Console.WriteLine("===============================================");
Console.WriteLine("\t\t*****My Biodata*****");
Console.WriteLine("Nama saya adalah {0}",a);
                        Console.WriteLine(". Saya lahir di {0}",b);//menampilkan ke layar
Console.Write("Saya tinggal di {0}",c);//menampilkan ke layar
                        Console.Write(". Saya beragama {0}",d);//menampilkan ke layar
                        Console.WriteLine(" dan Hobby saya {0}",e);//menampilkan ke layar
Console.WriteLine("Yang terpenting adalah prinsip hidupku {0}",f);//menampilkan ke layar
Console.ReadLine();

}
}
}

EXCEPTION HANDLING


Program aplikasi C# untuk mengontrol kesalahan apabila user salah menginput. Secara otomatis akan menampilkan pesan eror.


using System;

namespace Exception_Handling
{
class latihan8
{
[STAThread]
static void Main(string[] args)
{
double a,b,d;
string c;
try
{
Console.Write("Angka 1 : ");
a=Convert.ToInt32(Console.ReadLine());
Console.Write("+, -,* ,/ : ");
c=Convert.ToString(Console.ReadLine());
Console.Write("Angka 2 : ");
b=Convert.ToInt32(Console.ReadLine());
switch(c)
{
case "+" : d=a+b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
case "-" : d=a-b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
case "*" : d=a*b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
case "/" : d=a/b;
Console.WriteLine("Hasilnya adalah : {0}",d);
Console.ReadLine();
break;
default  :Console.WriteLine("Tanda yang anda masukkan salah");
break;
}
}
catch//menangani apabila inputan salah
{
Console.WriteLine("Maaf Inputan Anda salah, silahkan coba lagi");
Console.ReadLine();
}
}
}
}