Array adalah suatu struktur yang terdiri sejumlah elemen yang memiliki tipe data yang sama. Elemen-elemen array tersusun secara sekuensial dalam memmory komputer. Array dapat berupa satu dimensi, dua dimensi, tiga dimensi ataupun banyak dimensi ( multi dimensi ). Bentuk umum array sendiri antara lain :
<tipe data> || Nama Array = new < tipe data>[m];
Berikut ini contoh program sederhana tentang input nilai mahasiswa , silahkan di simak baik-baik :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] nama = new string[20];
int[] quiz = new int[100];
int[] uts = new int[100];
int[] uas = new int[100];
double[] total = new double[100];
string[] huruf = new string[20];
int i, n = 0;
Console.Write("Masukan Jumlah Mahasiswa = ");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
Console.WriteLine("Masukan data Mahasiswa ke-" + i);
Console.WriteLine("\t Masukan Mahasiswa = ");
nama[i] = Console.ReadLine();
Console.Write("\tMasukan Nilai Quiz = ");
quiz[i] = int.Parse(Console.ReadLine());
Console.Write("\tMasukan Nilai UTS = ");
uts[i] = int.Parse(Console.ReadLine());
Console.Write("\tMasukan Nilai UAS = ");
uas[i] = int.Parse(Console.ReadLine());
total[i] = 0.2 * quiz[1] + 0.4 * uts[i] + 0.4 * uas[i];
Console.WriteLine();
if (total[i] >= 80 && total[i] <= 100)
{
huruf[i] = "A ";
}
else if (total[i] >= 60 && total[i] <= 79)
{
huruf[i] = "B";
}
else if (total[i] >= 40 && total[i] <= 59)
{
huruf[i] = "C ";
}
else if (total[i] >= 20 && total[i] <= 39)
{
huruf[i] = "D ";
}
if (total[i] >= 0 && total[i] <= 19)
{
huruf[i] = "E ";
}
}
Console.Clear();
Console.WriteLine("=======================================");
Console.WriteLine(" Sistem Akademik UKRIM ");
Console.WriteLine("============================================================");
Console.WriteLine(" No | Nama Mahasiswa \tQuiz \tUTS \tUAS \t Total \t Nilai ");
Console.WriteLine("------------------------------------------------------------");
for (i = 1; i <= n; i++)
{
Console.WriteLine(i + " " + nama[i] + "\t" + quiz[i] + "\t" + uts[i] + "\t" + uas[i] + "\t" + total[i] + "\t" + huruf[i]);
}
Console.WriteLine("==============================================");
Console.WriteLine(" TERIMA KASIH ");
Console.Read();
}
}
}
Hasil Compiler Program
<tipe data> || Nama Array = new < tipe data>[m];
Program Input Nilai Mahasiswa dengan Array ( C# / C Sharp ) |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] nama = new string[20];
int[] quiz = new int[100];
int[] uts = new int[100];
int[] uas = new int[100];
double[] total = new double[100];
string[] huruf = new string[20];
int i, n = 0;
Console.Write("Masukan Jumlah Mahasiswa = ");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
Console.WriteLine("Masukan data Mahasiswa ke-" + i);
Console.WriteLine("\t Masukan Mahasiswa = ");
nama[i] = Console.ReadLine();
Console.Write("\tMasukan Nilai Quiz = ");
quiz[i] = int.Parse(Console.ReadLine());
Console.Write("\tMasukan Nilai UTS = ");
uts[i] = int.Parse(Console.ReadLine());
Console.Write("\tMasukan Nilai UAS = ");
uas[i] = int.Parse(Console.ReadLine());
total[i] = 0.2 * quiz[1] + 0.4 * uts[i] + 0.4 * uas[i];
Console.WriteLine();
if (total[i] >= 80 && total[i] <= 100)
{
huruf[i] = "A ";
}
else if (total[i] >= 60 && total[i] <= 79)
{
huruf[i] = "B";
}
else if (total[i] >= 40 && total[i] <= 59)
{
huruf[i] = "C ";
}
else if (total[i] >= 20 && total[i] <= 39)
{
huruf[i] = "D ";
}
if (total[i] >= 0 && total[i] <= 19)
{
huruf[i] = "E ";
}
}
Console.Clear();
Console.WriteLine("=======================================");
Console.WriteLine(" Sistem Akademik UKRIM ");
Console.WriteLine("============================================================");
Console.WriteLine(" No | Nama Mahasiswa \tQuiz \tUTS \tUAS \t Total \t Nilai ");
Console.WriteLine("------------------------------------------------------------");
for (i = 1; i <= n; i++)
{
Console.WriteLine(i + " " + nama[i] + "\t" + quiz[i] + "\t" + uts[i] + "\t" + uas[i] + "\t" + total[i] + "\t" + huruf[i]);
}
Console.WriteLine("==============================================");
Console.WriteLine(" TERIMA KASIH ");
Console.Read();
}
}
}
Hasil Compiler Program
0 komentar
Posting Komentar