Selasa, 24 Mei 2011

CSharp (C#) Mencari Nilai Terbesar & Terkecil Dalam Array


using System;
class Program{
static void Main(string[]
args){
Console.Write("Jmlh data : ");
int[]
bil = new int
     [int.Parse(Console.ReadLine())];
for (int i = 0; i < bil.Length; i++){
     Console.Write("bil {0}: ", i + 1);
     bil[i] = int.Parse
  (Console.ReadLine());
}



tampil(bil);
Console.WriteLine();
Console.WriteLine("Terbesar: {0}, Terkecil: {1}"
     , maks(bil), min(bil));
Console.ReadKey();
    }
static int maks(int[] bil){
int
maks = bil[0];

for (int i = 1; i < bil.Length; i++)
     if
(maks < bil[i])

  maks = bil[i];
return
maks;

    }
static int min(int[] bil){
int
min = bil[0];

for (int i = 1; i < bil.Length; i++)
     if
(min > bil[i])

  min = bil[i];
return
min;

    }
static void tampil(int[]
bil){

Console.WriteLine();
Console.Write("bil : ");
foreach
(int i in bil)

     Console.Write("{0} ", i);
    }
}

0 comments:

Klampok Child | XKom | Win7Aero