Dibawah ini adalah contoh program Exception HAndling dalam C#.
using System;
namespace Exception_Handling_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int r,x;
string status;
double []p=new double[5];
double []q=new double[5];
double []mean=new double[5];
string []name= new string[50];
try
{
Console.Write("How Many Students? ");
r=Convert.ToInt32(Console.ReadLine());
for (x=0;x<r;x++)
{
Console.WriteLine("\nData ke-{0}",x+1);
Console.Write("Name : ");
name[x]=Console.ReadLine();
Console.Write("Mid Exam : ");
p[x]=Convert.ToDouble(Console.ReadLine());
Console.Write("Final Exam : ");
q[x]=Convert.ToDouble(Console.ReadLine());
}
for (x=0;x<r;x++)
{
mean[x]=(p[x]+q[x])/2;
}
Console.WriteLine("\n\n");
Console.WriteLine("No\tName\t\tMid Exam\tFinal Exam\tAverage\t\tStatus");
Console.WriteLine("------------------------------------------------------------------------------");
for (x=0;x<r;x++)
{
if (mean[x]>=60)
{
Console.WriteLine("{0}\t{1}\t\t{2}\t{3}\t{4}\t\tOke",x+1,name[x],p[x],q[x],mean[x]);
}
else
{
Console.WriteLine("{0}\t{1}\t\t{2}\t{3}\t{4}\t\tNot Oke",x+1,name[x],p[x],q[x],mean[x]);
}
}
}
catch
{
Console.WriteLine("Inputan salah!");
}
Console.ReadLine();
}
}
}
Contoh Program Exception Handling dalam C#
Posted by
putri
, Sunday, March 6, 2011 at 9:10 PM, in
Contoh Program Array dalam C#
Posted by
putri
, at 9:10 PM, in
Dibawah ini adalah contoh program array dengan menggunakan bahasa C#.
using System;
namespace Array_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int r,x;
string status;
double []p=new double[5];
double []q=new double[5];
double []mean=new double[5];
string []name= new string[50];
Console.Write("How Many Students? ");
r=Convert.ToInt32(Console.ReadLine());
for (x=0;x<r;x++)
{
Console.WriteLine("\nData ke- {0} ",x+1);
Console.Write("Name : ");
name[x]=Console.ReadLine();
Console.Write("Mid Exam : ");
p[x]=Convert.ToDouble(Console.ReadLine());
Console.Write("Final Exam : ");
q[x]=Convert.ToDouble(Console.ReadLine());
}
for (x=0;x<r;x++)
{
mean[x]=(p[x]+q[x])/2;
}
Console.WriteLine("\n\n");
Console.WriteLine("No\tName\t\tMid Exam\tFinal Exam\tAverage\t\tStatus");
Console.WriteLine("------------------------------------------------------------------------------");
for (x=0;x<r;x++)
{
if (mean[x]>=60)
{
Console.WriteLine("{0}\t{1}\t\t{2}\t\t{3}\t\t{4}\t\tOke",x+1,name[x],p[x],q[x],mean[x]);
}
else
{
Console.WriteLine("{0}\t{1}\t{2}\t\t{3}\t\t{4}\t\tNo Oke",x+1,name[x],p[x],q[x],mean[x]);
}
}
Console.ReadLine();
}
}
}
using System;
namespace Array_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int r,x;
string status;
double []p=new double[5];
double []q=new double[5];
double []mean=new double[5];
string []name= new string[50];
Console.Write("How Many Students? ");
r=Convert.ToInt32(Console.ReadLine());
for (x=0;x<r;x++)
{
Console.WriteLine("\nData ke- {0} ",x+1);
Console.Write("Name : ");
name[x]=Console.ReadLine();
Console.Write("Mid Exam : ");
p[x]=Convert.ToDouble(Console.ReadLine());
Console.Write("Final Exam : ");
q[x]=Convert.ToDouble(Console.ReadLine());
}
for (x=0;x<r;x++)
{
mean[x]=(p[x]+q[x])/2;
}
Console.WriteLine("\n\n");
Console.WriteLine("No\tName\t\tMid Exam\tFinal Exam\tAverage\t\tStatus");
Console.WriteLine("------------------------------------------------------------------------------");
for (x=0;x<r;x++)
{
if (mean[x]>=60)
{
Console.WriteLine("{0}\t{1}\t\t{2}\t\t{3}\t\t{4}\t\tOke",x+1,name[x],p[x],q[x],mean[x]);
}
else
{
Console.WriteLine("{0}\t{1}\t{2}\t\t{3}\t\t{4}\t\tNo Oke",x+1,name[x],p[x],q[x],mean[x]);
}
}
Console.ReadLine();
}
}
}
Contoh Program Kalkulator Sederhana dalam C#
Posted by
putri
, at 2:14 PM, in
Dibawah ini adalah contoh program kalkulator sederhana dengan menggunakan bahasa C#.
using System;
namespace Kalkulator_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
decimal z,x,y;
string pilih;
Console.Write("Angka 1 : ");
x=Convert.ToDecimal(Console.ReadLine());
Console.Write("+, -, *, / : ");
pilih=Console.ReadLine();
Console.Write("Angka 2 : ");
y=Convert.ToDecimal(Console.ReadLine());
switch(pilih)
{
case "+" : z=x+y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
case "-" : z=x-y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
case "*" : z=x*y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
case "/" : z=x/y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
}
Console.ReadLine();
}
}
}
using System;
namespace Kalkulator_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
decimal z,x,y;
string pilih;
Console.Write("Angka 1 : ");
x=Convert.ToDecimal(Console.ReadLine());
Console.Write("+, -, *, / : ");
pilih=Console.ReadLine();
Console.Write("Angka 2 : ");
y=Convert.ToDecimal(Console.ReadLine());
switch(pilih)
{
case "+" : z=x+y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
case "-" : z=x-y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
case "*" : z=x*y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
case "/" : z=x/y;
Console.WriteLine("Jumlah adalah {0}",z);
break;
}
Console.ReadLine();
}
}
}
Contoh Program Mencari Angka Terbesar dalam C#
Posted by
putri
, at 2:12 PM, in
Dibawah ini adalah contoh program mencari angka terbesar dengan menggunakan bahasa C#.
using System;
namespace Perbandingan_Angka_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int x,y,z;
Console.Write("A = ? ");
x=Convert.ToInt32(Console.ReadLine());
Console.Write("B = ? ");
y=Convert.ToInt32(Console.ReadLine());
Console.Write("C = ? ");
z=Convert.ToInt32(Console.ReadLine());
if(x>y && x>z)
{
Console.WriteLine("Bilangan terbesar adalah {0}",x);
}
if(y>x && y>z)
{
Console.WriteLine("Bilangan terbesar adalah {0}",y);
}
if(z>x && z>y)
{
Console.WriteLine("Bilangan terbesar adalah {0}",z);
}
Console.ReadLine();
}
}
}
using System;
namespace Perbandingan_Angka_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int x,y,z;
Console.Write("A = ? ");
x=Convert.ToInt32(Console.ReadLine());
Console.Write("B = ? ");
y=Convert.ToInt32(Console.ReadLine());
Console.Write("C = ? ");
z=Convert.ToInt32(Console.ReadLine());
if(x>y && x>z)
{
Console.WriteLine("Bilangan terbesar adalah {0}",x);
}
if(y>x && y>z)
{
Console.WriteLine("Bilangan terbesar adalah {0}",y);
}
if(z>x && z>y)
{
Console.WriteLine("Bilangan terbesar adalah {0}",z);
}
Console.ReadLine();
}
}
}
Contoh Program Faktorial dalam C#
Posted by
putri
, at 2:08 PM, in
Dibawah ini adalah contoh program mencari faktorial dengan menggunakan bahasa C#.
using System;
namespace Faktorial_0320100024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int n,fak,k;
Console.Write("Masukkan Angka: ");
n=Convert.ToInt32(Console.ReadLine());
if(n==0)
{
Console.WriteLine("Hasil Faktorialnya adalah 1");
Console.ReadLine();
}
else
{
fak=1;
for(k=1;k<=n;k++)
{
fak=fak*k;
}
Console.WriteLine("Hasil Faktorialnya adalah {0}",fak);
Console.ReadLine();
}
}
}
}
using System;
namespace Faktorial_0320100024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int n,fak,k;
Console.Write("Masukkan Angka: ");
n=Convert.ToInt32(Console.ReadLine());
if(n==0)
{
Console.WriteLine("Hasil Faktorialnya adalah 1");
Console.ReadLine();
}
else
{
fak=1;
for(k=1;k<=n;k++)
{
fak=fak*k;
}
Console.WriteLine("Hasil Faktorialnya adalah {0}",fak);
Console.ReadLine();
}
}
}
}
Contoh Program Mencari Selisih Waktu dalam C#
Posted by
putri
, at 2:03 PM, in
Dibawah ini adalah contoh program untuk mencari selisih waktu dengan menggunakan bahasa C#.
using System;
namespace SelisihWaktu_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int h1,m1,s1,h2,m2,s2,h3,m3,s3;
Console.Write("Input Jam Awal : ");
h1=Convert.ToInt32(Console.ReadLine());
if(h1<=23)
{
Console.Write("Input Menit Awal : ");
m1=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Detik Awal : ");
s1=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Jam Akhir : ");
h2=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Menit Akhir : ");
m2=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Detik Akhir : ");
s2=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Waktu Awal Percakapan = {0}:{1}:{2} ",h1,m1,s1);
Console.WriteLine("Waktu Akhir Percakapan = {0}:{1}:{2} ",h2,m2,s2);
if(s1<=s2 && m1<=m2)
{
if(h1<=h2)
{
s3=s2-s1;
m3=m2-m1;
h3=h2-h1;
Console.WriteLine("\nSelisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1>=s2 && m1<=m2)
{
if(h1<=h2)
{
s3=(s2+60)-s1;
m3=(m2-1)-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1>=s2 && m1>=m2)
{
if(h1<=h2)
{
s3=(s2+60)-s1;
m3=(((m2-1)+60)-m1);
h3=(h2-1)-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1<=s2 && m1>=m2)
{
if(h1<=h2)
{
s3=s2-s1;
m3=((m2-1)+60)-m1;
h3=(h2-1)-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1<=s2 && m1<=m2)
{
if(h1==h2)
{
s3=s2-s1;
m3=m2-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1>=s2 && m1<=m2)
{
if(h1==h2)
{
s3=(s2+60)-s1;
m3=(m2-1)-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
}
else
{
Console.WriteLine("Data Jam yang Anda Masukkan salah");
}
Console.ReadLine();
}
}
}
using System;
namespace SelisihWaktu_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int h1,m1,s1,h2,m2,s2,h3,m3,s3;
Console.Write("Input Jam Awal : ");
h1=Convert.ToInt32(Console.ReadLine());
if(h1<=23)
{
Console.Write("Input Menit Awal : ");
m1=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Detik Awal : ");
s1=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Jam Akhir : ");
h2=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Menit Akhir : ");
m2=Convert.ToInt32(Console.ReadLine());
Console.Write("Input Detik Akhir : ");
s2=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Waktu Awal Percakapan = {0}:{1}:{2} ",h1,m1,s1);
Console.WriteLine("Waktu Akhir Percakapan = {0}:{1}:{2} ",h2,m2,s2);
if(s1<=s2 && m1<=m2)
{
if(h1<=h2)
{
s3=s2-s1;
m3=m2-m1;
h3=h2-h1;
Console.WriteLine("\nSelisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1>=s2 && m1<=m2)
{
if(h1<=h2)
{
s3=(s2+60)-s1;
m3=(m2-1)-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1>=s2 && m1>=m2)
{
if(h1<=h2)
{
s3=(s2+60)-s1;
m3=(((m2-1)+60)-m1);
h3=(h2-1)-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1<=s2 && m1>=m2)
{
if(h1<=h2)
{
s3=s2-s1;
m3=((m2-1)+60)-m1;
h3=(h2-1)-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1<=s2 && m1<=m2)
{
if(h1==h2)
{
s3=s2-s1;
m3=m2-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
if(s1>=s2 && m1<=m2)
{
if(h1==h2)
{
s3=(s2+60)-s1;
m3=(m2-1)-m1;
h3=h2-h1;
Console.WriteLine("Selisih Waktu Percakapan = {0}:{1}:{2}",h3,m3,s3);
}
}
}
else
{
Console.WriteLine("Data Jam yang Anda Masukkan salah");
}
Console.ReadLine();
}
}
}
Contoh Program Menulis dan Membaca dalam C#
Posted by
putri
, at 1:57 PM, in
Dibawah ini adalah contoh program menulis dan membaca dengan menggunakan bahasa C#.
using System;
namespace Tulis.Baca_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int um,y;
string nm,al,em,tl,pr;
Console.WriteLine("BIODATA DIRI");
Console.Write("\nNama : ");
nm=Console.ReadLine();
Console.Write("Alamat : ");
al=Console.ReadLine();
Console.Write("Umur : ");
um=Convert.ToInt32(Console.ReadLine());
Console.Write("E-mail : ");
em=Console.ReadLine();
Console.Write("Telp/Hp : ");
tl=Console.ReadLine();
Console.Write("Prodi : ");
pr=Console.ReadLine();
Console.Write("Tingkat : ");
y=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n\t\t\tData Telah Berhasil Diinput");
Console.Write("\n\t\t\tTerimakasih {0} {1} {2}",nm,pr,y);
Console.ReadLine();
}
}
}
using System;
namespace Tulis.Baca_024
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int um,y;
string nm,al,em,tl,pr;
Console.WriteLine("BIODATA DIRI");
Console.Write("\nNama : ");
nm=Console.ReadLine();
Console.Write("Alamat : ");
al=Console.ReadLine();
Console.Write("Umur : ");
um=Convert.ToInt32(Console.ReadLine());
Console.Write("E-mail : ");
em=Console.ReadLine();
Console.Write("Telp/Hp : ");
tl=Console.ReadLine();
Console.Write("Prodi : ");
pr=Console.ReadLine();
Console.Write("Tingkat : ");
y=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n\t\t\tData Telah Berhasil Diinput");
Console.Write("\n\t\t\tTerimakasih {0} {1} {2}",nm,pr,y);
Console.ReadLine();
}
}
}
Subscribe to:
Posts (Atom)