Syntax Dasar C#

Contoh Syntax Dasar dalam C#

namespace dasar
 {
     class Program
     {
         public static void Main(string[] args)
         {
             //Variable
             string a;
             int c;
             int d;
             int e;
             int total;
             int rata;

             //Inputan
             Console.Write("Masukkan nama anda = ");
             a=Console.ReadLine();
             Console.Write("Masukkan nilai 1= ");
             c=Convert.ToInt32(Console.ReadLine());
             Console.Write("Masukkan nilai 2= ");
             d=Convert.ToInt32(Console.ReadLine());
             Console.Write("Masukkan nilai 3= ");
             e=Convert.ToInt32(Console.ReadLine());

             //proses
             total=c+d+e;
             rata=(c+d+e)/3;


             //Output
             Console.WriteLine();
             Console.WriteLine("Nama anda adalah = {0}",a);
             Console.WriteLine("\nNilai 1 = {0}",c);
             Console.WriteLine("\nNilai 2 = {0}",d);
             Console.WriteLine("\nNilai 3 = {0}",e);
             Console.WriteLine("\nTotal nilai anda = {0}",total);
             Console.WriteLine("\nRata-rata anda = {0}",rata);

             Console.Write("Press any key to continue . . . ");
             Console.ReadKey(true);
         }
     }
 }

dan isi hasil Runningnya

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s