#include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAX 30 #define DELAY 10000000 #define TRUE 1 #define FALSE 0 #define INPUT 'i' #define OUTPUT 'o' #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif void BubbleSort(int*, int), Swap(int*, int*), InputOutput(int*, const int, const char), Delay(void), FreeBuffer(int*); int main(int argc, char *argv[]) { system("COLOR 5"); int *buffer = NULL, max; printf("Implementasi Bubble Sort\nMasukkan banyak data [max:30] : "); scanf("%d",&max); fflush(stdin); if((max > FALSE) && (max <= MAX)) { buffer = (int*)calloc(max,sizeof(int)); InputOutput(buffer,max,INPUT); printf("\nData yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); BubbleSort(buffer,max); printf("\nData setelah disorting : "); InputOutput(buffer,max,OUTPUT); FreeBuffer(buffer); } TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } void BubbleSort(int* buffer, int max) { int i, j; for(i = 0; i < max; ++i) { for(j = 0; j < max-i; ++j) { if(*(buffer+j) > *(buffer+(j+TRUE))) { // if(buffer[j] > buffer[j+TRUE]) { Swap((buffer+j),(buffer+(j+TRUE))); // Swap(&(*(buffer+j)),&(*(buffer+(j+TRUE)))); } } } } void Swap(int* buffer1, int* buffer2) { int tmp = *buffer1; *buffer1 = *buffer2; *buffer2 = tmp; } void InputOutput(int* buffer, const int max, const char STAT) { int i; /* switch(STAT) { case(INPUT) : { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE)); scanf("%d",&buffer[i]); fflush(stdin); } } break; case(OUTPUT) : { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); Delay(); } } break; default : break; } */ if('i' == STAT) { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE)); scanf("%d",&buffer[i]); fflush(stdin); } } else if('o' == STAT) { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); Delay(); } } } void Delay(void) { int i = FALSE; while(i < DELAY) { ++i; } } void FreeBuffer(int* buffer) { free(buffer); buffer = NULL; }
Tuesday, November 29, 2011
Bubble Sort dalam bahasa C
Shell Sort dalam bahasa C
# #include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAX 100 #define INPUT 'i' #define OUTPUT 'o' #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif // int CheckForBadSorting(int*, const int); void ShellSortPass(int*, const int, const int); void ShellSort(int*, const int); void InputOutput(int*, const int, const char); void FreeBuffer(int*); int main(int argc, char* argv[]) { system("COLOR 5"); int *buffer = NULL, max; printf("Implementasi Shell Sort\nMasukkan jumlah data [MAX:100] : "); scanf("%d",&max); fflush(stdin); if((max > 0) && (max <= MAX)) { buffer = (int*)calloc(max,sizeof(int)); InputOutput(buffer,max,INPUT); printf("\nData yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); ShellSort(buffer,max); printf("\nData setelah disorting : "); InputOutput(buffer,max,OUTPUT); FreeBuffer(buffer); /* if(CheckForBadSorting(buffer,max)) { goto MARK; } else { InputOutput(buffer,max,OUTPUT); } */ } /* MARK : if(buffer != NULL) { FreeBuffer(buffer); } */ TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } /* int CheckForBadSorting(int* buffer, const int max) { int i; for(i = 1; i < max; ++i) { if(buffer[i-1] > buffer[i]) { printf("Bad Sorting!"); return(1); } } return(0); } */ void ShellSortPass(int* buffer, const int max, const int interval) { int i; for(i = 0; i < max; ++i) { int j, tmp = buffer[i]; for(j = i-interval; j >= 0; j -= interval) { if(buffer[j] <= tmp) { break; } buffer[j+interval] = buffer[j]; } buffer[j+interval] = tmp; } } void ShellSort(int* buffer, const int max) { int CiuraIntervals[] = {701, 301, 132, 57, 23, 10, 4, 1}, IntervalIdx = 0, interval = CiuraIntervals[0]; double ExtendCiuraMultiplier = 2.3; if(max > interval) { while(max > interval) { --IntervalIdx; interval = (int)(interval*ExtendCiuraMultiplier); } } else { while(max < interval) { ++IntervalIdx; interval = CiuraIntervals[IntervalIdx]; } } while(interval > 1) { ++IntervalIdx; if(IntervalIdx >= 0) { interval = CiuraIntervals[IntervalIdx]; } else { interval = (int)(interval/ExtendCiuraMultiplier); } ShellSortPass(buffer,max,interval); } } void InputOutput(int* buffer, const int max, const char STAT) { int i; if('i' == STAT) { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+1),(i+1)); scanf("%d",&buffer[i]); fflush(stdin); } } else if('o' == STAT) { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); } } } void FreeBuffer(int* buffer) { free(buffer); buffer = NULL; }
bucket Sort dalam bahasa C
#include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAX 100 #define INPUT 'i' #define OUTPUT 'o' #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif void InputOutput(int*, const int, const char); void BucketSort(int*, const int); void FreeBuffer(int*); int main(int argc, char *argv[]) { system("COLOR 5"); int *buffer = NULL, max; printf("Implementasi Bucket Sort\nMasukkan jumlah data [MAX:100] : "); scanf("%d",&max); fflush(stdin); if((max > 0) && (max <= MAX)) { buffer = (int*)calloc(max,sizeof(int)); InputOutput(buffer,max,INPUT); printf("\nData yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); BucketSort(buffer,max); printf("\nData setelah disorting : "); InputOutput(buffer,max,OUTPUT); FreeBuffer(buffer); } TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } void InputOutput(int* buffer, const int max, const char STAT) { int i; if('i' == STAT) { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+1),(i+1)); scanf("%d",&buffer[i]); fflush(stdin); } } else if('o' == STAT) { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); } } } void BucketSort(int* buffer, const int max) { int i, j, *count = (int*)calloc(max,sizeof(int)); for(i = 0; i < max; ++i) { count[i] = 0; } for(i = 0; i < max; ++i) { ++(count[buffer[i]]); } for(i = 0, j = 0; i < max; ++i) { for(; count[i] > 0; --(count[i])) { buffer[j++] = i; } } FreeBuffer(count); } void FreeBuffer(int* buffer) { free(buffer); buffer = NULL; }
Quick Sort dalam bahasa C
#include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAX 30 #define INPUT 'i' #define OUTPUT 'o' #define TRUE 1 #define FALSE 0 #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif int ChoosePivot(int, int); void InputOutput(int*, const int, const char), QuickSort(int*, int, int), Swap(int*, int*), FreeBuffer(int*); int main(int argc, char *argv[]) { system("COLOR 5"); int *buffer = NULL, max; printf("Implementasi Quick Sort [Ascending]\nJumlah data [MAX:30] : "); scanf("%d",&max); fflush(stdin); if((max > FALSE) && (max <= MAX)) { buffer = (int*)calloc(max,sizeof(int)); InputOutput(buffer,max,INPUT); printf("\n1. Data yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); QuickSort(buffer,FALSE,(max-TRUE)); printf("\n2. Data setelah disorting : "); InputOutput(buffer,max,OUTPUT); FreeBuffer(buffer); } TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } void InputOutput(int* buffer, int max, const char STAT) { int i; if(INPUT == STAT) { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE)); scanf("%d",&buffer[i]); fflush(stdin); } } else if(OUTPUT == STAT) { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); } } } int ChoosePivot(int top, int bottom) { return((top+bottom)/2); } void QuickSort(int* buffer, int bottom, int top) { int i, j, k, pivot; // m = bottom, n = top; if(bottom < top) { pivot = ChoosePivot(bottom,top); Swap(&buffer[bottom],&buffer[pivot]); i = bottom+TRUE; j = top; k = buffer[bottom]; while(i <= j) { while((i <= top) && (buffer[i] <= k)) { ++i; } while((j >= bottom) && (buffer[j] > k)) { --j; } if(i < j) { Swap(&buffer[i],&buffer[j]); } } Swap(&buffer[bottom],&buffer[j]); QuickSort(buffer,bottom,(j-TRUE)); QuickSort(buffer,(j+TRUE),top); } } void Swap(int* buffer1, int* buffer2) { int tmp = *buffer1; *buffer1 = *buffer2; *buffer2 = tmp; } void FreeBuffer(int* buffer) { free(buffer); buffer = NULL; }
Exchange sort dalam bahasa C
#include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAX 30 #define DELAY 10000000 #define TRUE 1 #define FALSE 0 #define INPUT 'i' #define OUTPUT 'o' #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif void ExchangeSort(int*, int), Swap(int*, int*), InputOutput(int*, const int, const char), Delay(void), FreeBuffer(int*); int main(int argc, char *argv[]) { system("COLOR 5"); int *buffer = NULL, max; printf("Implementasi Exchange Sort\nMasukkan banyak data [max:30] : "); scanf("%d",&max); fflush(stdin); if((max > FALSE) && (max <= MAX)) { buffer = (int*)calloc(max,sizeof(int)); InputOutput(buffer,max,INPUT); printf("\nData yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); ExchangeSort(buffer,max); printf("\nData setelah disorting : "); InputOutput(buffer,max,OUTPUT); FreeBuffer(buffer); } TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } void ExchangeSort(int* buffer, int max) { int i, j; for(i = 0; i < (max-TRUE); ++i) { for(j = (i+TRUE); j < max; ++j) { if(*(buffer+i) > *(buffer+(j))) { Swap((buffer+i),(buffer+(j))); // Swap(&(*(buffer+j)),&(*(buffer+(j+TRUE)))); } } } } void Swap(int* buffer1, int* buffer2) { int tmp = *buffer1; *buffer1 = *buffer2; *buffer2 = tmp; } void InputOutput(int* buffer, int max, const char STAT) { int i; if('i' == STAT) { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE)); scanf("%d",&buffer[i]); fflush(stdin); } } else if('o' == STAT) { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); Delay(); } } } void Delay(void) { int i = FALSE; while(i < DELAY) { ++i; } } void FreeBuffer(int* buffer) { free(buffer); buffer = NULL; }
Gnome sort dalam bahasa C
#include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAX 100 #define INPUT 'i' #define OUTPUT 'o' #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif void InputOutput(int*, const int, const char); void GnomeSort(int*, const int); void Swap(int*, int*); void FreeBuffer(int*); int main(int argc, char *argv[]) { system("COLOR 3"); int *buffer = NULL, max; printf("Implementasi Gnome Sort\nMasukkan jumlah data [MAX:100] : "); scanf("%d",&max); fflush(stdin); if((max > 0) && (max <= MAX)) { buffer = (int*)calloc(max,sizeof(int)); InputOutput(buffer,max,INPUT); printf("\nData yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); GnomeSort(buffer,max); printf("\nData setelah disorting : "); InputOutput(buffer,max,OUTPUT); FreeBuffer(buffer); } TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } void InputOutput(int* buffer, const int max, const char STAT) { int i; if('i' == STAT) { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+1),(i+1)); scanf("%d",&buffer[i]); fflush(stdin); } } else if('o' == STAT) { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); } } } void GnomeSort(int* buffer, const int max) { int i; for(i = 1; i < max;) { if(buffer[i-1] <= buffer[i]) { ++i; } else { Swap(&buffer[i],&buffer[i-1]); --i; if(!i) { i = 1; } } } } void Swap(int* buffer1, int* buffer2) { int tmp = *buffer1; *buffer1 = *buffer2; *buffer2 = tmp; } void FreeBuffer(int* buffer) { free(buffer); buffer = NULL; }
Insertion Sort dalam bahasa C
#include <stdio.h> #include <conio.h> #include <stdlib.h> #define MAX 30 #define DELAY 10000000 #define TRUE 1 #define FALSE 0 #define INPUT 'i' #define OUTPUT 'o' #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif void InsertionSort(int*, const int); void InputOutput(int*, const int, const char); void Delay(void); void FreeBuffer(int*); int main(int argc, char *argv[]) { system("COLOR 5"); int *buffer = NULL, max; printf("Implementasi Insertion Sort\nMasukkan banyak data [max:30] : "); scanf("%d",&max); fflush(stdin); if((max > FALSE) && (max <= MAX)) { buffer = (int*)calloc(max,sizeof(int)); InputOutput(buffer,max,INPUT); printf("\nData yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); InsertionSort(buffer,max); printf("\nData setelah disorting : "); InputOutput(buffer,max,OUTPUT); FreeBuffer(buffer); } TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } void InsertionSort(int* buffer, const int max) { int i, j, tmp; for(i = 1; i < max; ++i) { tmp = buffer[i]; j = i-TRUE; while((j >= FALSE) && (buffer[j] > tmp)) { buffer[j+TRUE] = buffer[j]; --j; } buffer[j+TRUE] = tmp; } } void InputOutput(int* buffer, const int max, const char STAT) { int i; if('i' == STAT) { for(i = 0; i < max; ++i) { printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE)); scanf("%d",&buffer[i]); fflush(stdin); } } else if('o' == STAT) { for(i = 0; i < max; ++i) { printf("%d ",buffer[i]); Delay(); } } } void Delay(void) { int i = FALSE; while(i < DELAY) { ++i; } } void FreeBuffer(int* buffer) { free(buffer); buffer = NULL; }
Counting Sort dalam bahasa C
#include <stdio.h> #include <conio.h> #include <stdlib.h> #define UINT unsigned int #define MAX 100 #define INPUT 'i' #define OUTPUT 'o' #define _MY_DEBUG #if defined(_MY_DEBUG) #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__); #else #define TRACE_LINE #endif void InputOutput(long*, const long, const char); int CountingSort(long*, const long, const long); void FreeBuffer(long*); int main(int argc, char *argv[]) { system("COLOR 5"); long *buffer = NULL, max; printf("Implementasi Counting Sort\nMasukkan jumlah data [MAX:100] : "); scanf("%ld",&max); fflush(stdin); if((max > 0) && (max <= MAX)) { buffer = (long*)calloc(max,sizeof(long)); InputOutput(buffer,max,INPUT); printf("\nData yang anda masukkan : "); InputOutput(buffer,max,OUTPUT); if(!CountingSort(buffer,max,65535)) { // 2147483647 /* Jika user menginputkan nilai lebih besar atau sama dengan 65535 kedalam array buffer, maka Fungsi CountingSort tidak akan bekerja sesuai dengan fungsinya atau bisa mengakibatkan program Error / akan terjadi Segmentation Fault */ printf("\nData setelah disorting : "); InputOutput(buffer,max,OUTPUT); } FreeBuffer(buffer); } TRACE_LINE; getch(); fflush(stdin); return(EXIT_SUCCESS); } void InputOutput(long* buffer, const long max, const char STAT) { long i; if('i' == STAT) { for(i = 0; i < max; ++i) { printf("%ld. Data ke-%ld : ",(i+1),(i+1)); scanf("%ld",&buffer[i]); fflush(stdin); } } else if('o' == STAT) { for(i = 0; i < max; ++i) { printf("%ld ",buffer[i]); } } } int CountingSort(long* buffer, const long max, const long value) { long i, j, OutputPos; long* counts = (long*)calloc(value,sizeof(long)); if(counts == NULL) { printf("\nError : No Memory Available for Counts!"); return(1); } else { for(i = 0; i < max; ++i) { ++counts[buffer[i]]; } OutputPos = 0; for(i = 0; i < value; ++i) { for(j = 0; j < counts[i]; ++j) { buffer[OutputPos] = i; ++OutputPos; } } FreeBuffer(counts); } return(0); } void FreeBuffer(long* buffer) { free(buffer); buffer = NULL; }
procedure counting sort
Procedure CountingSort (Input/output T:array [1..N] of integer)
{Mengurutkan Tabel T integer [1..N] dengan pencacahan, dimana range atau rentang nilainya [1..k] dengan hasil akhir T terurut menaik , dengan asumsi:Nilai N (jumlah elemen T) dan k diketahui
Asumsi : Nilai N (jumlah elemen T) dan k diketahui, rentang nilai untuk elemen T integer antara 1..k }
Kamus
C : array [1..k] of integer {Tabel array pencacahan}
i, j : Integer {indek perulangan}
c : Integer {jumlah elemen T yang sudah diisi pada pembentukan kembali}
Algoritma
for i = 1 to k do {Loop 1}
C[ i ] <-- 0;
endfor
for i = 1 to N do {Loop 2}
C[ T[ i ] ] <-- C[ T [ i ] ] + 1
endfor
C <-- 0
for i = 1 to k do {Loop 3}
if C[ i ] < > 0 then
for j = 1 to C[ i ] do {Loop 4}
C <-- C + 1
T[C] <-- i
endfor;
endif;
endfor;
{Mengurutkan Tabel T integer [1..N] dengan pencacahan, dimana range atau rentang nilainya [1..k] dengan hasil akhir T terurut menaik , dengan asumsi:Nilai N (jumlah elemen T) dan k diketahui
Asumsi : Nilai N (jumlah elemen T) dan k diketahui, rentang nilai untuk elemen T integer antara 1..k }
Kamus
C : array [1..k] of integer {Tabel array pencacahan}
i, j : Integer {indek perulangan}
c : Integer {jumlah elemen T yang sudah diisi pada pembentukan kembali}
Algoritma
for i = 1 to k do {Loop 1}
C[ i ] <-- 0;
endfor
for i = 1 to N do {Loop 2}
C[ T[ i ] ] <-- C[ T [ i ] ] + 1
endfor
C <-- 0
for i = 1 to k do {Loop 3}
if C[ i ] < > 0 then
for j = 1 to C[ i ] do {Loop 4}
C <-- C + 1
T[C] <-- i
endfor;
endif;
endfor;
program inheritance mobil dalam c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication27
{
class kendaraan
{
public kendaraan()
{
Console.WriteLine("bahan bakar = bensin");
}
public kendaraan(string tipe)
{
Console.WriteLine("bahan bakar = {0}",tipe);
}
}
class mobilsport : kendaraan
{
public mobilsport()
{
Console.WriteLine("NOS added");
}
public mobilsport(string tipe):base(tipe)
{
Console.WriteLine("NOS added");
}
}
class Program
{
static void Main(string[] args)
{
mobilsport ob = new mobilsport();
}
}
}
program inheritance handphone 2 dalam c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace inheritance
{
class Handphone
{
public string nama;
public void call()
{
Console.WriteLine("telepon dari {0}",nama);
}
public void sms()
{
Console.WriteLine("sms dari {0}",nama);
}
}
class Blackberry : Handphone
{
public void b1()
{
base.nama="blackbery";
Console.WriteLine("bbm");
base.call();
base.sms();
}
}
class nokia : Handphone
{
public void b2()
{
base.nama="nokia";
Console.WriteLine("camera");
base.call();
base.sms();
}
}
class dakota : Blackberry
{
public void d1()
{
{
base.nama="dakota";
Console.WriteLine("touch");
base.call();
base.sms();
}
}
class Program
{
static void Main(string[] args)
{
Blackberry obj1 = new Blackberry();
obj1.b1();
nokia obj2 = new nokia();
obj2.b2();
dakota obj3 = new dakota();
obj3.d1();
}
}
}
}
program inheritance handphone dalam c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace inheritance
{
class Handphone
{
public void call()
{
Console.WriteLine("call");
}
public void sms()
{
Console.WriteLine("sms");
}
}
class Blackberry : Handphone
{
public void b1()
{
Console.WriteLine("bbm");
base.call();
base.sms();
}
}
class nokia : Handphone
{
public void b2()
{
Console.WriteLine("camera");
base.call();
base.sms();
}
}
class dakota : Blackberry
{
public void d1()
{
{
Console.WriteLine("touch");
base.call();
base.sms();
}
}
class Program
{
static void Main(string[] args)
{
Blackberry obj1 = new Blackberry();
obj1.b1();
nokia obj2 = new nokia();
obj2.b2();
dakota obj3 = new dakota();
obj3.d1();
}
}
}
}
Wednesday, November 23, 2011
Monday, November 21, 2011
penjualan tiket pesawat dalam pascal
Program menjual_tiket;
Uses wincrt;
Type mat = array[1..10,1..10] of integer;
Function free(a: mat): Boolean;
Var
I,j : integer;
found: boolean;
Begin
Found:= true;
I:= 1;
While (found) and (i<=8) do
begin
J:=1;
While (found) and (j<=5) do
If a[I,j] =0 then
Found:=false
Else
J:= j+1;
I:= i+1;
end;
free:= found;
End;
Function cek_damping(a: mat): boolean;
Var
I,j : integer;
Found : boolean;
Begin
Found := false;
I:= 1;
While (not found) and (i<=8) do
begin
J:=1;
While (not found) and (j<5) do
If (a[I,j] <> 0) and (a[I,j+1]<>0) then
Found := true
Else
J:= j+1;
I:= i+1;
end;
Cek_damping:= found;
End;
Function kursi_pinggir(a: mat): boolean;
Var
I,j : integer;
Found : boolean;
Begin
Found := false;
j:= 1;
While (not found) and (j<=5) do
begin
I:=1;
While (not found) and (i<8) do
If a[I,j] <> 0 then
Found := true
Else
i:= i+1;
j:= j+4;
end;
kursi_pinggir:= found;
End;
Function kursi_nonton(a: mat): boolean;
Var
I,j : integer;
Found : boolean;
Begin
Found := false;
I:= 2;
While (not found) and (i<=8) do
begin
J:=1;
While (not found) and (j<5) do
If (a[I,j] <> 0) and (a[I,j+1]<>0) then
Found := true
Else
J:= j+1;
I:= i+1;
end;
kursi_nonton:= found;
End;
procedure rubah(n : integer; var a:mat);
var
i,j : integer;
begin
For i:= 1 to 8 do
For j:= 1 to 5 do
If a[I,j] = n then
If a[I,j] = n then
A[I,j] :=0;
end;
Var
y: string;
a: mat;
i,j,n: integer;
hasil, hasil1, hasil2, hasil3 : boolean;
Begin
For i:= 1 to 8 do
For j:= 1 to 5 do
A[I,j] := ((i*5)-5+j);
For i:= 1 to 8 do
begin
For j:= 1 to 5 do
Write(a[I,j], ' ');
Writeln;
End;
repeat
Writeln('masukkan no tempat duduk yang anda inginkan');
Readln(n);
clrscr;
hasil := free(a);
writeln('bangku yang anda pesan masih dalam keadaan ', hasil);
writeln;
rubah(n,a);
For i:= 1 to 8 do
begin
For j:= 1 to 5 do
Write(a[I,j], ' ');
Writeln;
End;
writeln('apakah masih ada yang ingin memesan tiket pesawat???? (Y/N) ');
readln(y);
until y = 'n';
hasil1:= cek_damping(a);
writeln(hasil1);
hasil2:= kursi_pinggir(a);
writeln(hasil2);
hasil3:= kursi_nonton(a);
writeln(hasil3);
End.
program konversi desimal ke heksa dalam pascal
Program Convert_Decimal_To_heksa;
Uses wincrt;
Const N = 100;
Type Stack = record
Isi : Array[1..N]of integer;
Top : integer;
end;
Procedure CreateStack(Var S:Stack);
begin
S.Top := 0;
end;
Function IsFull(S:Stack):boolean;
begin
IsFull := (S.Top = N);
end;
Function IsEmpty(S:Stack):boolean;
begin
IsEmpty := (S.Top = 0);
end;
Procedure Push(X:integer; var S:Stack);
begin
If Not IsFull(S) then
begin
S.Top := S.Top + 1;
S.Isi[S.Top] := X;
end;
end;
Procedure Pop(var X:integer; var S:Stack);
begin
IF NOt IsEmpty(S) then
begin
X := S.Isi[S.Top];
S.Top := S.Top - 1;
end;
end;
Procedure Convert(var S:Stack; X:integer);
var Sisa : integer;
begin
Repeat
Sisa := X mod 16;
X := X div 16;
Push(Sisa,S);
Until X = 0 ;
end;
function rubah (x:integer):string;
begin
if x=10 then
rubah:='A';
if x=11 then
rubah:='B';
if x=12 then
rubah:='C';
if x=13 then
rubah:='D';
if x=14 then
rubah:='E';
if x=15 then
rubah:='F';
end;
{Main Program}
Var S : Stack;
X,i,biner: integer;
biner2:string;
Begin
writeln('+---------------------------------+');
Writeln('|Program Konversi Desimal ke Biner|');
writeln('+---------------------------------+');
Writeln;
Write('Masukkan angka Desimal : ');
readln(X);
writeln;
write('Angka heksadesimal dari ',X,' adalah ');
CreateStack(S);
Convert(S,X);
for i:=1 to S.Top do
begin
Pop(biner,S);
if biner>=10 then
begin
biner2:=rubah (biner);
write(biner2);
end
else
write(biner);
end;
End.
program queue dalam pascal
Program Queveueeueueueueueueueuee;
Uses wincrt;
Const N = 100;
Type Queve = record
isi : Array[1..N]of integer;
head:integer;
tail: integer;
end;
Procedure CreateQueve(Var S:Queve);
begin
S.head:=0;
S.tail:=0;
end;
Function IsFull(S:Queve):boolean;
begin
IsFull := (S.head = 1) and (S.tail = N);
end;
Function IsEmpty(S:Queve):boolean;
begin
IsEmpty := (S.head = 0 ) and (S.tail = 0);
end;
Procedure add(X:integer; var S:Queve);
begin
If Not IsFull(S) then
begin
S.tail := S.tail + 1;
S.isi[S.tail] := X;
if S.head=0 then
S.head:=S.head+1;
end;
end;
Procedure remove(var X:integer; var S:Queve);
var i:integer;
begin
IF NOt IsEmpty(S) then
begin
X:=S.isi[S.head];
for i:= 2 to S.tail do
S.isi[i-1]:=S.isi[i];
S.tail :=S.tail - 1;
if S.tail=0 then
S.head:=S.head-1;
end;
end;
{Main Program}
Var S : Queve;
X,i,z,m,Y: integer;
Begin
write('masukan jumlah data ');readln(X);
CreateQueve(S);
for i:= 1 to X do
begin
write('masukan data ke',i,' : ');readln(m);
add(m,S);
end;
writeln;
write('jumlah data yang akan dikeluarkan ');readln(Y);
writeln('data yang dikeluarkan : ');
for i:= 1 to Y do
begin
remove(z,S);
writeln(z);
end;
writeln;
writeln('data yang tersisa : ');
for i:= 1 to S.tail do
writeln(S.isi[i]);
writeln;
writeln('S.tail berada di elemen ke ',S.tail);
writeln('S.head berada di elemen ke ',S.head);
End.
mengubah desimal menjadi biner dalam pascal
program ubah_desimal_binary;
uses wincrt;
const n=100;
type stack = record
elemen:array[1..n]of integer;
top:integer;
end;
function isiempty(s:stack):boolean;
begin
isiempty:=(s.top=0);
end;
function isifull(s:stack):boolean;
begin
isifull:=(s.top=n);
end;
procedure create_stack(var s:stack);
begin
s.top:=0;
end;
procedure push(var s:stack; a:integer);
begin
if not (isifull(s)) then
begin
s.top:=s.top+1;
s.elemen[s.top]:=a;
end
end;
procedure pop(var s:stack; var a:integer);
begin
if not (isiempty(s)) then
begin
a:=s.elemen[s.top];
s.top:=s.top-1;
end
end;
function convert(a:integer):integer;
var y,x:integer;
z,tmp:string;
s:stack;
begin
create_stack(s);
while a>0 do
begin
y:=a mod 2;
push(s,y);
a:=a div 2;
end;
tmp:='';
while not isiempty(s) do
begin
pop(s,a);
str(a,z);
tmp:=tmp+z;
end;
val(tmp,a,a);
convert:=a;
end;
var i,hasil:integer;
begin
write('Masukan nilai desimal = ');readln(i);
hasil:=convert(i);
writeln(hasil);
end.
program matrik dalam pascal
program matiks;
uses wincrt;
type
arin=array [1..100] of integer;
function cari(b:arin;m,n,x:integer):integer;
var
i,j,domp:integer;
begin
domp:=0;
for i:=1 to m do
begin
for j:= 1 to n do
begin
if b[j]=x then
domp:=domp+1;
end;
end;
cari:=domp;
end;
var
a:arin;
i,j,m,n,x,domp:integer;
begin
write('masukan jumlah baris : ');readln(n);
write('masukan jumlah kolom : ');readln(m);
for i:=1 to m do
begin
for j:= 1 to n do
begin
write('a[',i,',',j,'] : ');readln(a[j]);
end;
end;
write('masukan bilangan yang dicari : ');readln(x);
domp:=cari(a,m,n,x);
writeln('jadi bilangan yang dicari ada ',domp);
end.
statistik (mean dan titik tengah) dalam pascal
Program interval;
uses wincrt;
type tabin=array [1..200] of integer;
function mean (a:tabin; n:integer):real;
var
i,domp:integer;
begin
domp:=0;
for i:= 1 to n do
domp:=domp+a[i];
mean:=domp/n;
end;
function ttktngah(a:tabin; n:integer):real;
begin
if n mod 2 = 0 then
ttktngah:=(a[n div 2]+a[(n div 2)+1])/2
else
ttktngah:=(a[(n div 2)+1]);
end;
var
a:tabin;
i,n:integer;
hsl,hsl2:real;
begin
write('masukan batas : ');readln(n);
for i:= 1 to n do
begin
write('masukan data ke ',i,' : ');readln(a[i]);
end;
hsl:=mean(a,n);
write('mean : ',hsl:0:2);
hsl2:=ttktngah(a,n);
writeln;
writeln('titik tengah : ',hsl2:0:2);
end.
program warnet dalam pascal
program wartel;
uses wincrt;
type waktu=record
jam:longint;
menit:longint;
detik:longint;
end;
function hitungselisih(jam1,jam2:waktu):longint;
begin
hitungselisih:=((jam2.jam*3600)+(jam2.menit*60)+jam2.detik)-((jam1.jam*3600)+(jam1.menit*60)+jam1.detik);
end;
function hitungbiaya(jam1,jam2:waktu):longint;
var
temp1:longint;
begin
temp1:=hitungselisih(jam1,jam2);
if (temp1 mod 30 >0) then
hitungbiaya:=((temp1 div 30)*250)+250
else
hitungbiaya:=(temp1 div 30)*250;
end;
var
jam1,jam2:waktu;
biaya,lama:longint;
begin
writeln('masukan waktu awal ');
write('jam = ');readln(jam1.jam);
write('menit = ');readln(jam1.menit);
write('detik = ');readln(jam1.detik);
writeln;
writeln('masukan waktu akhir ');
write('jam = ');readln(jam2.jam);
write('menit = ');readln(jam2.menit);
write('detik = ');readln(jam2.detik);
writeln;
biaya:=hitungbiaya(jam1,jam2);
lama:=hitungselisih(jam1,jam2);
writeln('lama percakapan = ',lama,' detik');
writeln('biaya menelpon = ',biaya);
end.
program stack dalam pascal
program stackkkkk;
uses wincrt;
type stack=record
isistack:array [1..100] of integer;
top:integer;
end;
const n:integer=100;
procedure createstack(var s:stack);
begin
s.top:=0;
end;
function isfull(s:stack):boolean;
begin
isfull:=(s.top=n);
end;
function isempty(s:stack):boolean;
begin
isempty:=(s.top=0);
end;
procedure push(var s:stack;x:integer);
begin
if not isfull(s) then
begin
s.top:=s.top+1;
s.isistack[s.top]:=x;
end;
end;
procedure pop(var s:stack;x:integer);
begin
if not isempty(s) then
begin
x:=s.isistack[s.top];
s.top:=s.top-1;
end;
end;
procedure biner(x:integer;var s:stack);
var
a,z:integer;
begin
a:=x;
repeat
begin
z:=a mod 2;
push( s ,z );
a:=a div 2;
end
until (a = 1);
push( s,a);
end;
var
s:stack;
x,a:integer;
begin
readln(x);
biner (x,s);
repeat
begin
pop (s,a);
writeln(a);
end
until s.top=0;
end.
menghitung jumlah, perkalian dan rata-rata dalam pascal
program ulang;
uses wincrt;
type a=array[1..10000] of longint;
var
T:a;
n,temp,temp2,i,j:longint;
c:real;
begin
i:=1;
repeat
write('masukan angka = ');read(n);
T[i]:=n;
i:=i+1;
until (n>9999);
clrscr;
temp:=T[1];
write('penjumlahan = ',T[1],'+');
for j:=2 to (i-2) do
begin
write(T[j]);
temp:=temp+T[j];
if (j<>(i-2)) then
write('+')
else
write('=');
end;
write(temp);
writeln;
temp2:=T[1];
write('perkalian = ',T[1],'*');
for j:=2 to (i-2) do
begin
write(T[j]);
temp2:=temp2*T[j];
if (j<>(i-2)) then
write('*')
else
write('=');
end;
write(temp2);
writeln;
c:=(temp/(i-2));
writeln('rata-rata = ',c:0:2);
end.
program warnet dalam pascal
program wartel;
uses wincrt;
type waktu=record
jam:longint;
menit:longint;
detik:longint;
end;
function hitungselisih(jam1,jam2:waktu):longint;
begin
hitungselisih:=((jam2.jam*3600)+(jam2.menit*60)+jam2.detik)-((jam1.jam*3600)+(jam1.menit*60)+jam1.detik);
end;
function hitungbiaya(jam1,jam2:waktu):longint;
var
temp1:longint;
begin
temp1:=hitungselisih(jam1,jam2);
if (temp1 mod 30 >0) then
hitungbiaya:=((temp1 div 30)*250)+250
else
hitungbiaya:=(temp1 div 30)*250;
end;
var
jam1,jam2:waktu;
biaya,lama:longint;
begin
writeln('masukan waktu awal ');
write('jam = ');readln(jam1.jam);
write('menit = ');readln(jam1.menit);
write('detik = ');readln(jam1.detik);
writeln;
writeln('masukan waktu akhir ');
write('jam = ');readln(jam2.jam);
write('menit = ');readln(jam2.menit);
write('detik = ');readln(jam2.detik);
writeln;
biaya:=hitungbiaya(jam1,jam2);
lama:=hitungselisih(jam1,jam2);
writeln('lama percakapan = ',lama,' detik');
writeln('biaya menelpon = ',biaya);
end.
Thursday, November 17, 2011
mencari nilai max min secara rekursif
Procedure rekursifmaxmin(input T[1..N] array of integer, i:integer, j:integer, output max,min:integer)
Kamus
T1,T2: array
min1,min2,max1,max2:integer
Algoritma
if i=j then
max <-- T[i]
min <-- T[i]
else
if i=j-1 then
if T[j]> T[i] then
max <-- T[j]
min <-- T[i]
else
max <-- T[i]
min <-- T[j]
endif
else
mid <-- (i+j) div 2
maxmin(T1,i,mid,max1,min1)
maxmin(T2,mid+1,j,2max,min2)
if max1>max2 then
max <-- max1
else
max <-- max2
endif
if min1 > min2 then
min <-- min2
else
min <-- min1
endif
endif
Wednesday, November 16, 2011
penjualan minuman dalam pascal
Program hitung;
uses wincrt;
const m:longint=5;
type barang=record
kode:longint;
nama:string;
harga:longint;
berat:longint;
stok:longint;
pembelian:longint;
end;
function cekharga(uang,harga:longint):boolean;
var
cek:boolean;
begin
cek:=false;
if (uang>=harga) then
begin
cek:=true;
end;
cekharga:=cek;
end;
function cekberat(berat,barang:longint):boolean;
var
cek:boolean;
begin
cek:=false;
if (barang>=berat) then
begin
cek:=true;
end;
cekberat:=cek;
end;
function cekstok(stok:longint):boolean;
var
cek:boolean;
begin
cek:=true;
if (stok=0) then
begin
cek:=false;
end;
cekstok:=cek;
end;
procedure hitungstok(var stok:longint);
begin
stok:=stok-1;
end;
procedure beli(var uang:longint; harga:longint );
begin
uang:=uang-harga;
end;
procedure penuh(var kranjang:longint; berat:longint );
begin
kranjang:=kranjang-berat;
end;
var
product,simpan:array [1..50] of barang;
i,n,uang,kranjang,temp:longint;
pil:string;
begin
temp:=0;
product[1].kode:=1;
product[1].nama:=('coke');
product[1].harga:=5000;
product[1].berat:=350;
product[1].stok:=5;
product[2].kode:=2;
product[2].nama:=('sprite');
product[2].harga:=3500;
product[2].berat:=275;
product[2].stok:=7;
product[3].kode:=3;
product[3].nama:=('bear');
product[3].harga:=6000;
product[3].berat:=400;
product[3].stok:=9;
product[4].kode:=4;
product[4].nama:=('fanta');
product[4].harga:=4000;
product[4].berat:=275;
product[4].stok:=4;
product[5].kode:=5;
product[5].nama:=('redbull');
product[5].harga:=6000;
product[5].berat:=350;
product[5].stok:=5;
for i:= 1 to m do
begin
simpan[i]:=product[i];
simpan[i].pembelian:=0;
end;
writeln('|-------------------------------------|');
writeln('|kode |nama |harga |berat |stok |');
writeln('|-------------------------------------|');
writeln('| 1 |coke |5000 |350 | ',product[1].stok,' |');
writeln('| 2 |sprite |3500 |275 | ',product[2].stok,' |');
writeln('| 3 |bear |6000 |400 | ',product[3].stok,' |');
writeln('| 4 |fanta |4000 |275 | ',product[4].stok,' |');
writeln('| 5 |redbull |6000 |350 | ',product[5].stok,' |');
writeln('|-------------------------------------|');
writeln;
writeln;
write('masukan jumlah uang anda : ');readln(uang);
write('masukan kapasitas keranjang anda : ');readln(kranjang);
writeln;
write('apakah anda ingin berbelanja (y/t) ');readln(pil);
writeln;
while (pil='y') do
begin
write('masukan kode minuman yg ingin dibeli : ');readln(n);
writeln;
if (n<=m) then
begin
if (cekstok(product[n].stok)=true) then
begin
if (cekberat(product[n].berat,kranjang)=true) and (cekharga(uang,product[n].harga)=true) then
begin
beli(uang,product[n].harga);
penuh(kranjang,product[n].berat);
hitungstok(product[n].stok);
simpan[n].pembelian:=simpan[n].pembelian+1;
temp:=temp+1;
write('apakah anda ingin berbelanja lagi (y/t) ');readln(pil);
writeln;
end
else
begin
clrscr;
writeln('maav anda tidak bisa melakukan transaksi');
writeln('terima kasih');
writeln;
writeln('sisa uang anda : ',uang);
writeln('sisa kapasitas kranjang : ',kranjang);
writeln;
if (temp>0) then
begin
writeln('barang yg telah dibeli : ');
for i:= 1 to m do
begin
if (simpan[i].pembelian>0) then
begin
writeln(simpan[i].nama,' jumlah yg dibeli ',simpan[i].pembelian);
end
end;
end
else
writeln('tidak ada barang yg dibeli');
writeln;
writeln;
writeln('sisa minuman');
writeln;
writeln('|-------------------------------------|');
writeln('|kode |nama |harga |berat |stok |');
writeln('|-------------------------------------|');
writeln('| 1 |coke |5000 |350 | ',product[1].stok,' |');
writeln('| 2 |sprite |3500 |275 | ',product[2].stok,' |');
writeln('| 3 |bear |6000 |400 | ',product[3].stok,' |');
writeln('| 4 |fanta |4000 |275 | ',product[4].stok,' |');
writeln('| 5 |redbull |6000 |350 | ',product[5].stok,' |');
writeln('|-------------------------------------|');
writeln;
pil:=' ';
end;
end
else
begin
writeln('maav stok kosong');
writeln;
write('apakah anda ingin berbelanja lagi (y/t) ');readln(pil);
writeln;
end;
end
else
begin
writeln('maaf kode barang tidak terdaftar');
writeln;
write('apakah anda ingin berbelanja lagi (y/t) ');readln(pil);
writeln;
end;
end;
if (pil='t') then
begin
clrscr;
writeln('terima kasih');
writeln;
writeln('sisa uang anda : ',uang);
writeln('sisa kapasitas kranjang : ',kranjang);
writeln;
if (temp>0) then
begin
writeln('barang yg telah dibeli : ');
for i:= 1 to m do
begin
if (simpan[i].pembelian>0) then
begin
writeln(simpan[i].nama,' jumlah yg dibeli ',simpan[i].pembelian);
end
end;
end
else
writeln('tidak ada barang yg dibeli');
writeln;
writeln;
writeln('sisa minuman');
writeln;
writeln('|-------------------------------------|');
writeln('|kode |nama |harga |berat |stok |');
writeln('|-------------------------------------|');
writeln('| 1 |coke | 5000 | 350 | ',product[1].stok,' |');
writeln('| 2 |sprite | 3500 | 275 | ',product[2].stok,' |');
writeln('| 3 |bear | 6000 | 400 | ',product[3].stok,' |');
writeln('| 4 |fanta | 4000 | 275 | ',product[4].stok,' |');
writeln('| 5 |redbull | 6000 | 350 | ',product[5].stok,' |');
writeln('|-------------------------------------|');
writeln;
end;
end.
Tuesday, November 15, 2011
program bank dalam c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class bank
{
private int amount;
private static int total;
public void deposit(int amt)
{
amount += amt;
total = total + amt;
}
public void withdraw(int amt)
{
if (amount < amt)
{
Console.WriteLine("Saldo Kurang");
}
else
{
amount -= amt;
total = total - amt;
}
}
public void cek_saldo()
{
Console.WriteLine("Jumlah Saldo Anda = {0}", amount);
}
public static void show_total()
{
Console.WriteLine("Jumlah Uang di Bank = {0}", total);
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("Jumlah Nasabah = ");
int n_nasabah = int.Parse(Console.ReadLine());
bank[] nasabah = new bank[n_nasabah + 1];
for (int i = 1; i <= n_nasabah; i++)
{
nasabah[i] = new bank();
}
while (true)
{
Console.WriteLine("Pilihan : ");
Console.WriteLine(" 1. Menabung");
Console.WriteLine(" 2. Mengambil Uang");
Console.WriteLine(" 3. Cek_Saldo");
Console.WriteLine(" 4. Cek_saldo_bank");
Console.WriteLine(" 5. keluar");
Console.Write("Pilih : ");
int pilih = int.Parse(Console.ReadLine());
int no_rek;
int jumlah;
switch (pilih)
{
case 1:
{
Console.Write("Nomor Rekening Anda : ");
no_rek = int.Parse(Console.ReadLine());
Console.Write("Jumlah Uang ");
jumlah = int.Parse(Console.ReadLine());
nasabah[no_rek].deposit(jumlah);
break;
}
case 2:
{
Console.Write("Nomor Rekening Anda : ");
no_rek = int.Parse(Console.ReadLine());
Console.Write("Jumlah Uang ");
jumlah = int.Parse(Console.ReadLine());
nasabah[no_rek].withdraw(jumlah);
break;
}
case 3:
{
Console.Write("Nomor Rekening Anda : ");
no_rek = int.Parse(Console.ReadLine());
nasabah[no_rek].cek_saldo();
break;
}
case 4:
{
bank.show_total();
Console.WriteLine();
break;
}
case 5:
return;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class bank
{
private int amount;
private static int total;
public void deposit(int amt)
{
amount += amt;
total = total + amt;
}
public void withdraw(int amt)
{
if (amount < amt)
{
Console.WriteLine("Saldo Kurang");
}
else
{
amount -= amt;
total = total - amt;
}
}
public void cek_saldo()
{
Console.WriteLine("Jumlah Saldo Anda = {0}", amount);
}
public static void show_total()
{
Console.WriteLine("Jumlah Uang di Bank = {0}", total);
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("Jumlah Nasabah = ");
int n_nasabah = int.Parse(Console.ReadLine());
bank[] nasabah = new bank[n_nasabah + 1];
for (int i = 1; i <= n_nasabah; i++)
{
nasabah[i] = new bank();
}
while (true)
{
Console.WriteLine("Pilihan : ");
Console.WriteLine(" 1. Menabung");
Console.WriteLine(" 2. Mengambil Uang");
Console.WriteLine(" 3. Cek_Saldo");
Console.WriteLine(" 4. Cek_saldo_bank");
Console.WriteLine(" 5. keluar");
Console.Write("Pilih : ");
int pilih = int.Parse(Console.ReadLine());
int no_rek;
int jumlah;
switch (pilih)
{
case 1:
{
Console.Write("Nomor Rekening Anda : ");
no_rek = int.Parse(Console.ReadLine());
Console.Write("Jumlah Uang ");
jumlah = int.Parse(Console.ReadLine());
nasabah[no_rek].deposit(jumlah);
break;
}
case 2:
{
Console.Write("Nomor Rekening Anda : ");
no_rek = int.Parse(Console.ReadLine());
Console.Write("Jumlah Uang ");
jumlah = int.Parse(Console.ReadLine());
nasabah[no_rek].withdraw(jumlah);
break;
}
case 3:
{
Console.Write("Nomor Rekening Anda : ");
no_rek = int.Parse(Console.ReadLine());
nasabah[no_rek].cek_saldo();
break;
}
case 4:
{
bank.show_total();
Console.WriteLine();
break;
}
case 5:
return;
}
}
}
}
}
Wednesday, November 9, 2011
mencari niali terkecil array 2 dimensi
program matiks;
uses wincrt;
type
tab=record
kolom:integer;
baris:integer;
bil:integer;
end;
type
arin=array [1..100] of integer;
procedure min(b:arin;m,n:integer;var c:tab);
var
i,j,domp,temp:integer;
begin
domp:=b[1];
c.baris:=1;
c.kolom:=1;
for i:=1 to m do
begin
for j:= 1 to n do
begin
if domp>=b[j] then
begin
domp:=b[j];
c.baris:=i;
c.kolom:=j;
end;
end;
end;
c.bil:=domp;
end;
var
a:arin;
i,j,m,n,x:integer;
domp:tab;
begin
write('masukan jumlah baris : ');readln(n);
write('masukan jumlah kolom : ');readln(m);
for i:=1 to m do
begin
for j:= 1 to n do
begin
write('a[',i,',',j,'] : ');readln(a[j]);
end;
end;
writeln;
min(a,m,n,domp);
writeln('jadi bilangan terkecil adalah : ',domp.bil,' berada di a[',domp.baris,',',domp.kolom,']');
end.
uses wincrt;
type
tab=record
kolom:integer;
baris:integer;
bil:integer;
end;
type
arin=array [1..100] of integer;
procedure min(b:arin;m,n:integer;var c:tab);
var
i,j,domp,temp:integer;
begin
domp:=b[1];
c.baris:=1;
c.kolom:=1;
for i:=1 to m do
begin
for j:= 1 to n do
begin
if domp>=b[j] then
begin
domp:=b[j];
c.baris:=i;
c.kolom:=j;
end;
end;
end;
c.bil:=domp;
end;
var
a:arin;
i,j,m,n,x:integer;
domp:tab;
begin
write('masukan jumlah baris : ');readln(n);
write('masukan jumlah kolom : ');readln(m);
for i:=1 to m do
begin
for j:= 1 to n do
begin
write('a[',i,',',j,'] : ');readln(a[j]);
end;
end;
writeln;
min(a,m,n,domp);
writeln('jadi bilangan terkecil adalah : ',domp.bil,' berada di a[',domp.baris,',',domp.kolom,']');
end.
Subscribe to:
Posts (Atom)