Program Pencari Nilai Terbesar dan Terbesar Kedua


Written in Pascal.

  1. {
  2.         twovar.pas
  3.  
  4.         Copyright 2010 Hafizh Herdi Naufal <twohnuvo@gmail.com>
  5.         website : http://twoh.web.id
  6.         This program is free software; you can redistribute it and/or modify
  7.         it under the terms of the GNU General Public License as published by
  8.         the Free Software Foundation; either version 2 of the License, or
  9.         (at your option) any later version.
  10.  
  11.         This program is distributed in the hope that it will be useful,
  12.         but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.         GNU General Public License for more details.
  15.  
  16.         You should have received a copy of the GNU General Public License
  17.         along with this program; if not, write to the Free Software
  18.         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19.         MA 02110-1301, USA.
  20. }
  21.  
  22.  
  23. program bahtera_nasyid;
  24.  
  25. uses crt;
  26.  
  27. var i,max1,max2,data : integer;
  28.     x : array[1..100] of integer;
  29.  
  30. procedure inputdata;
  31. var count: integer;
  32. begin
  33.      write(‘Masukkan banyaknya data : ‘);
  34.      readln(data);
  35.      for count:=1 to data do
  36.         begin
  37.             write(‘Masukkan data ke ‘,count,‘ : ‘);
  38.             readln(x[count]);
  39.         end;
  40. end;
  41.  
  42. procedure tukar(var data1,data2:integer);
  43. var temp: integer;
  44. begin
  45.     temp:=data1;
  46.     data1:=data2;
  47.     data2:=temp;
  48. end;
  49.  
  50. procedure urutGelembung;
  51. var j:integer;
  52. begin
  53.         for i:= 2 to data do
  54.         begin
  55.             for j:= data downto i do
  56.             begin
  57.                 if ( x[j1] <= x[j]) then
  58.                         tukar(x[j1],x[j]);
  59.             end;
  60.         end;
  61. end;
  62.  
  63. procedure satudua;
  64. begin
  65.     max1:=x[1];
  66.     max2:=x[2];
  67.     writeln(‘data terbesar pertama adalah : ‘,max1);
  68.     writeln(‘data terbesar kedua adalah : ‘,max2);
  69. end;
  70.  
  71. procedure testarray;
  72. begin
  73.     for i:=1 to data do
  74.     begin
  75.     writeln(‘Data ke ‘,i,‘ adalah : ‘, x[i]);
  76.     end;
  77. end;
  78.  
  79. procedure mainprog;
  80. begin
  81. clrscr;
  82. inputdata;
  83. urutGelembung;
  84. {testarray;} //mengecek keberhasilan pengurutan array, hilangkan "{}" untuk menjalankan
  85. satudua;
  86. readln;
  87. end;
  88.  
  89. BEGIN
  90.     {Program utama}
  91.     mainprog;
  92. END.
  93.  

Download here.

2 thoughts on “Program Pencari Nilai Terbesar dan Terbesar Kedua

    • Sama-sama gan~
      Ini udah yang menurutku paling simpel, dibuat procedure juga biar simpel, kalau mau bisa diilangin prosedurnya, bisa langsung dicopas codenya ke program utama~
      Nggak sulit lah untuk ukuran calon ahli matematika haha, sukses juga gan ^^

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s