program pola_Bintang;
uses crt;
var
n,m,i,j,k,l : integer;
PIL: CHAR;
begin
REPEAT
writeln('Program bintang');
writeln('==============');
write('Masukkan nilai untuk pola bintang = ');readln(n);
begin
for i := 1 to n do
begin
for j := n-i downto 1 do
begin
write(' ');
end;
for k:= 1 to (i-1+i) do
begin
write('*');
end;
writeln;
end;
end;
writeln;
write (' Apakah anda ingin mengisi kembali ?(Y/T) = ');readln(pil);
writeln;
until pil = 't';
end.
Sunday, 28 October 2012
Matriks identitas modifikasi (PASCAL)
program Matrik_identitas_modifikasi;
uses crt;
var
i,j,k,l : integer;
pil :char;
begin
repeat
begin
clrscr;
writeln('Program Matriks_Identitas_Modifikasi');
writeln('====================================');
write('Masukan ordo matrik = ' ); readln(i);
k := i;
if (k>0)and (k<=1000) then
begin
for j:=1 to i do
begin
for l:=1 to i do
begin
if (j=l) then
write(j)
else
write('0');
end;
writeln();
end;
end
else
writeln('inputan ',i,' tidak di perbolehkan');
writeln;
end;
writeln;
write (' Apakah anda ingin mengisi kembali ?(Y/T) = ');readln(pil);
until pil = 't';
end.
Tampilan :
uses crt;
var
i,j,k,l : integer;
pil :char;
begin
repeat
begin
clrscr;
writeln('Program Matriks_Identitas_Modifikasi');
writeln('====================================');
write('Masukan ordo matrik = ' ); readln(i);
k := i;
if (k>0)and (k<=1000) then
begin
for j:=1 to i do
begin
for l:=1 to i do
begin
if (j=l) then
write(j)
else
write('0');
end;
writeln();
end;
end
else
writeln('inputan ',i,' tidak di perbolehkan');
writeln;
end;
writeln;
write (' Apakah anda ingin mengisi kembali ?(Y/T) = ');readln(pil);
until pil = 't';
end.
Tampilan :
Program Deret Fibonacci [Pascal] Validasi y/n?
program Jumlah_deret_fibonacci;
uses crt;
Var
n,m,i,a,b,c,hasil : integer;
pilihan : char;
begin
repeat
clrscr;
writeln ('Program Hitung Jumlah Deret Fibonaccy');
writeln ('=====================================');
write ('Masukkan Banyaknya Deret : '); readln(n);
m := n ;
if (m >= 1000) and (m<1) then
begin
writeln (' Jumlah Deret Yang Anda Masukkan Salah ! ');
writeln (' 0 < Deret <= 1000 ');
write ('Masukkan Banyaknya Deret : '); readln(n);
end
else
hasil := 1;
a:= 0;
b:=1;
write ( a,' ', b,' ');
For i := 1 to n-1 do
begin
c:=a+b;
hasil := hasil + c;
write( c, ' ');
a:=b;
b:=c;
end;
writeln ('= ',hasil);
writeln (' ===================== ');
writeln (' INGIN MENGULANG ?(Y/T)');read(pilihan);
until pilihan = 't';
end.
tampilannya :
uses crt;
Var
n,m,i,a,b,c,hasil : integer;
pilihan : char;
begin
repeat
clrscr;
writeln ('Program Hitung Jumlah Deret Fibonaccy');
writeln ('=====================================');
write ('Masukkan Banyaknya Deret : '); readln(n);
m := n ;
if (m >= 1000) and (m<1) then
begin
writeln (' Jumlah Deret Yang Anda Masukkan Salah ! ');
writeln (' 0 < Deret <= 1000 ');
write ('Masukkan Banyaknya Deret : '); readln(n);
end
else
hasil := 1;
a:= 0;
b:=1;
write ( a,' ', b,' ');
For i := 1 to n-1 do
begin
c:=a+b;
hasil := hasil + c;
write( c, ' ');
a:=b;
b:=c;
end;
writeln ('= ',hasil);
writeln (' ===================== ');
writeln (' INGIN MENGULANG ?(Y/T)');read(pilihan);
until pilihan = 't';
end.
tampilannya :
Friday, 26 October 2012
Program fibonacci ( PASCAL) Repeat Until
program DeretFibonacci;
uses crt;
var
i,n,f,f1,f2 : longint;
pil:char;
begin
repeat
clrscr;
write(' MASUKKAN SUKU KE-N : ');readln(n);
f1 := 1;
f2 := 1;
if (n = 1) then
begin
writeln(' SUKU KE-1 ADALAH = 1');
end
else
begin
writeln(' SUKU KE-1 ADALAH = 1');
writeln(' SUKU KE-2 ADALAH = 1');
end;
for i:=3 to n do
begin
f:=f1+f2;
writeln(' SUKU KE-',i,' ADALAH = ',f);
f2:=f1;
f1:=f;
end;
write (' INGIN MENGULANG ?(Y/T)');readln(pil);
until pil = 't';
end.
Tampilan :
THANKS to AGUSTINUS RAHMAT SIJABAT
http://www.facebook.com/agustinusclairvoyant
=============================END=====================================
uses crt;
var
i,n,f,f1,f2 : longint;
pil:char;
begin
repeat
clrscr;
write(' MASUKKAN SUKU KE-N : ');readln(n);
f1 := 1;
f2 := 1;
if (n = 1) then
begin
writeln(' SUKU KE-1 ADALAH = 1');
end
else
begin
writeln(' SUKU KE-1 ADALAH = 1');
writeln(' SUKU KE-2 ADALAH = 1');
end;
for i:=3 to n do
begin
f:=f1+f2;
writeln(' SUKU KE-',i,' ADALAH = ',f);
f2:=f1;
f1:=f;
end;
write (' INGIN MENGULANG ?(Y/T)');readln(pil);
until pil = 't';
end.
Tampilan :
THANKS to AGUSTINUS RAHMAT SIJABAT
http://www.facebook.com/agustinusclairvoyant
=============================END=====================================
Program deret fibonaccy (dev-pascal)
program deret_fibonacci;
uses crt;
Var n,i,j,a,b,c,hasil : Integer;
begin
write ('Masukkan Banyaknya Deret : '); readln(n);
hasil := 2;
a:=1;
b:=1;
write (a,' ',b,' ');
For i := 1 to n-1 do
begin
for j := 1 to j do
begin
c:=a+b;
hasil := hasil + c;
write(c,' ');
a:=b;
b:=c;
end;
end;
write ('Hasil = ',hasil);
readln;
end.
Tampilan nya:
uses crt;
Var n,i,j,a,b,c,hasil : Integer;
begin
write ('Masukkan Banyaknya Deret : '); readln(n);
hasil := 2;
a:=1;
b:=1;
write (a,' ',b,' ');
For i := 1 to n-1 do
begin
for j := 1 to j do
begin
c:=a+b;
hasil := hasil + c;
write(c,' ');
a:=b;
b:=c;
end;
end;
write ('Hasil = ',hasil);
readln;
end.
Tampilan nya:
Fibonaccy |
Program Cetak Bintang Rata Kanan (PASCAL)
Program bintang;
uses crt;
var
m,n,i,j : integer;
begin
writeln('Masukkan Angka Untuk Gambar Segitiga : ');readln(n);
for i:=n downto 1 do
begin
for j:=i-1 downto 1 do
write(' ');
for m:=n-(i-1) downto 1 do
write('*');
writeln();
end;
readkey();
end.
Tampilannya sebagai berikut:
uses crt;
var
m,n,i,j : integer;
begin
writeln('Masukkan Angka Untuk Gambar Segitiga : ');readln(n);
for i:=n downto 1 do
begin
for j:=i-1 downto 1 do
write(' ');
for m:=n-(i-1) downto 1 do
write('*');
writeln();
end;
readkey();
end.
Tampilannya sebagai berikut:
Perkalian dua matriks (TURBO PASCAL)
Turbo Pascal : Menghitung perkalian dua matriks.
berikut ini adalah script pascal menghitung perkalian dua matriks.
Berikut script untuk matriks 1 :
Program Perkalian_Matriks;
uses wincrt;
var
m1,m2,mh:array[1..10,1..10] of integer;
b1,k1,x1,y1,a,b2,k2,x2,y2:longint;
begin;
write('masukkan jumlah baris matriks 1: '); readln(b1);
write('masukkan jumlah kolom matriks 1: '); readln(k1);
for x1:= 1 to b1 do
begin
for y1:= 1 to k1 do
begin
write('[',x1,':',y1,']='); readln(m1[x1,y1]);
end;
end;
writeln('matriks 1');
for x1:= 1 to b1 do
begin
for y1:= 1 to k1 do
begin
write(m1[x1,y1]:7);
end;writeln;
end;writeln;
ini adalah hasil matriks 1
Berikut script matriks 2 :
write('masukkan jumlah baris matriks 2: '); readln(b2);
write('masukkan jumlah kolom matriks 2: '); readln(k2);
for x2:= 1 to b2 do
begin
for y2:=1 to k2 do
begin
write('[',x2,':',y2,']='); readln(m2[x2,y2]);
end;
end;
writeln('matriks 2');
for x2:= 1 to b2 do
begin
for y2:= 1 to k2 do
begin
write(m2[x2,y2]:7);
end;writeln;
end;writeln;
ini adalah hasil matriks 2
Berikut adalah script perkalian kedua matriks di atas :
if k1=x2 then begin
writeln('Hasil perkalian matriksnya adalah');
for x1:= 1 to b1 do
begin
for a:=1 to k2 do
begin
for y1:= 1 to k1 do
begin
for y2:= a to k2 do
begin
for x2:=y1 to b2 do
begin
mh[x1,y2]:=mh[x1,y2]+m1[x1,y1]*m2[x2,y2];
if k1=y1 then
begin
write(mh[x1,y2]:7);
end;
x2:=b2;
end;
y2:=k2;
end;
end;
end;
writeln;
end;
end else
begin
writeln('Maaf operasi perkalian matriks tidak bisa dikerjakan karena');
writeln('karena kolom matriks1 (',k1,' kolom) tidak sama dengan baris matriks 2 (',x2,' baris)');
end;
end.
ini adalah hasil perkalian dua matriks di atas
terima kasih sudah membaca tutorial ini.
semoga bermanfaat bagi saudara-saudaraku semuanya.
amin.
berikut ini adalah script pascal menghitung perkalian dua matriks.
Berikut script untuk matriks 1 :
Program Perkalian_Matriks;
uses wincrt;
var
m1,m2,mh:array[1..10,1..10] of integer;
b1,k1,x1,y1,a,b2,k2,x2,y2:longint;
begin;
write('masukkan jumlah baris matriks 1: '); readln(b1);
write('masukkan jumlah kolom matriks 1: '); readln(k1);
for x1:= 1 to b1 do
begin
for y1:= 1 to k1 do
begin
write('[',x1,':',y1,']='); readln(m1[x1,y1]);
end;
end;
writeln('matriks 1');
for x1:= 1 to b1 do
begin
for y1:= 1 to k1 do
begin
write(m1[x1,y1]:7);
end;writeln;
end;writeln;
ini adalah hasil matriks 1
Berikut script matriks 2 :
write('masukkan jumlah baris matriks 2: '); readln(b2);
write('masukkan jumlah kolom matriks 2: '); readln(k2);
for x2:= 1 to b2 do
begin
for y2:=1 to k2 do
begin
write('[',x2,':',y2,']='); readln(m2[x2,y2]);
end;
end;
writeln('matriks 2');
for x2:= 1 to b2 do
begin
for y2:= 1 to k2 do
begin
write(m2[x2,y2]:7);
end;writeln;
end;writeln;
ini adalah hasil matriks 2
Berikut adalah script perkalian kedua matriks di atas :
if k1=x2 then begin
writeln('Hasil perkalian matriksnya adalah');
for x1:= 1 to b1 do
begin
for a:=1 to k2 do
begin
for y1:= 1 to k1 do
begin
for y2:= a to k2 do
begin
for x2:=y1 to b2 do
begin
mh[x1,y2]:=mh[x1,y2]+m1[x1,y1]*m2[x2,y2];
if k1=y1 then
begin
write(mh[x1,y2]:7);
end;
x2:=b2;
end;
y2:=k2;
end;
end;
end;
writeln;
end;
end else
begin
writeln('Maaf operasi perkalian matriks tidak bisa dikerjakan karena');
writeln('karena kolom matriks1 (',k1,' kolom) tidak sama dengan baris matriks 2 (',x2,' baris)');
end;
end.
ini adalah hasil perkalian dua matriks di atas
terima kasih sudah membaca tutorial ini.
semoga bermanfaat bagi saudara-saudaraku semuanya.
amin.
PROGRAM MATRIKS INVERS ORDO 2 X 2 (PASCAL)
MATRIKS INVERS ORDO 2 X 2
1. Invers Matriks Persegi
Definisi Invers Matriks 1:
Misalkan A dan B adalah dua matriks yang berordo 2 × 2 dan memenuhi
persamaan AB = BA = I2 maka matriks A adalah matriks invers dari matriks
B atau matriks B adalah matriks invers dari matriks A.
Definisi Invers Matriks 2:Untuk membuat program INVERS MATRIKS 2 x 2 di atas,berikut adalah script untuk membuatnya :
Program Invers_Matriks_2_x_2;
uses wincrt;
var
m1:array[1..10,1..10] of integer;
x1,y1:integer;
p,q,r,s,invers,a,b,c,d,i:real;
begin
write('Invers matriks berordo 2 x 2');
writeln;
for x1:= 1 to 2 do
begin
for y1:= 1 to 2 do
begin
write('masukkan data[',x1,':',y1,']='); readln(m1[x1,y1]);
end;
end;
writeln('matriks 1');
for x1:= 1 to 2 do
begin
for y1:= 1 to 2 do
begin
write(m1[x1,y1]:7);
end;writeln;
end;writeln;
begin
a:=m1[1,1];
b:=m1[1,2];
c:=m1[2,1];
d:=m1[2,2];
i:=(a*d)-(b*c);
end;
if not(i=0) then
begin
invers:=1/((a*d)-(b*c));
p:=d*invers;
q:=-b*invers;
r:=-c*invers;
s:=a*invers;
writeln('Hasil invers matriksnya adalah');
gotoxy(5,13);write(p:0:2);
gotoxy(13,13);write(q:0:2);
gotoxy(5,14);write(r:0:2);
gotoxy(13,14);write(s:0:2);
end else
begin
writeln('Maaf operasi invers matriks tidak bisa dikerjakan');
end;
end.
Tampilannya :
Program menghitung faktorial (PASCAL)
Berikut ini adalah script pascal dari suatu faktorial.
script ini digunakan untuk rumus N!/(N-R)!*R!
ini scriptnya....
begin
gotoxy(15,1);
writeln('Program perhitungan Kombinasi pada Faktorial');
gotoxy(30,2);
writeln('M. Ali Rusdi');
gotoxy(5,3);
write('masukkan nilai N = ');readln(n);
gotoxy(5,4);
write('masukkan nilai R = ');readln(r);
nr:= n-r;
gotoxy(5,5);
writeln('NR adalah = ',nr:0:0);
gotoxy(5,7);
write('faktorial dari N =');
faktorial(n,f1);
gotoxy(5,8);
write('faktorial dari R =');
faktorial(r,f2);
gotoxy(5,9);
write('faktorial dari N-R =');
faktorial(nr,f3);
c:=f1/(f3*f2);
gotoxy(8,10);
write('N!');
gotoxy(5,11);
write('_________ =',c:10:0);
gotoxy(5,12);
write('(N-R)!*R!');
end.
script ini digunakan untuk rumus N!/(N-R)!*R!
ini scriptnya....
Program menghitung_faktorial;
uses wincrt;
var
hasil,fak,c,n,nr,r,f1,f2,f3:real;
i:integer;
procedure faktorial(var fak,hasil:real);
begin
i:=1;
hasil:=1;
while i<= fak do
begin
hasil:= hasil*i;
i:=i+1;
end;
writeln(hasil:10:0);
end;
uses wincrt;
var
hasil,fak,c,n,nr,r,f1,f2,f3:real;
i:integer;
procedure faktorial(var fak,hasil:real);
begin
i:=1;
hasil:=1;
while i<= fak do
begin
hasil:= hasil*i;
i:=i+1;
end;
writeln(hasil:10:0);
end;
begin
gotoxy(15,1);
writeln('Program perhitungan Kombinasi pada Faktorial');
gotoxy(30,2);
writeln('M. Ali Rusdi');
gotoxy(5,3);
write('masukkan nilai N = ');readln(n);
gotoxy(5,4);
write('masukkan nilai R = ');readln(r);
nr:= n-r;
gotoxy(5,5);
writeln('NR adalah = ',nr:0:0);
gotoxy(5,7);
write('faktorial dari N =');
faktorial(n,f1);
gotoxy(5,8);
write('faktorial dari R =');
faktorial(r,f2);
gotoxy(5,9);
write('faktorial dari N-R =');
faktorial(nr,f3);
c:=f1/(f3*f2);
gotoxy(8,10);
write('N!');
gotoxy(5,11);
write('_________ =',c:10:0);
gotoxy(5,12);
write('(N-R)!*R!');
end.
Berikut Adalah Tampilannya :
Program MAtrik identitas terbalik (PASCAL)
program MAtrik_identitas_terbalik;
uses
WinCrt;
var
A,B,C:array[1..10,1..10] of integer;
X,Y,Z,KOL,BAR:integer;
begin
for X:=1 to 5 do
begin
for y:=1 to 5 do
begin
C[X,Y]:=0;
if X+Y=6 then C[X,Y]:=1;
write(C[X,Y]:4);
end;
writeln;
end;
end.
kalau dieksekusi hasilnya seperti ini :
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0
uses
WinCrt;
var
A,B,C:array[1..10,1..10] of integer;
X,Y,Z,KOL,BAR:integer;
begin
for X:=1 to 5 do
begin
for y:=1 to 5 do
begin
C[X,Y]:=0;
if X+Y=6 then C[X,Y]:=1;
write(C[X,Y]:4);
end;
writeln;
end;
end.
kalau dieksekusi hasilnya seperti ini :
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0
Program Fibonacci (PASCAL)
program
fibonacci;
| uses crt; |
| var |
| n: integer ; |
| i: integer ; |
| deret: array [ 1..100 ] of longint ; |
|
| begin |
| {deret fibonacci adalah deret yang merupakan hasil penjumlahan 2 bilangan sebelumnya} |
| {7 awal deret fibonacci = 1,1,2,3,5,8,13,...} |
| clrscr; |
| write ( 'Masukan jumlah deret :' ); |
| readln(n); |
| writeln ; |
| for i := 0 to n- 1 do |
| begin |
| if (i = 0 ) or (i = 1 ) then |
| begin |
| deret[i]:= 1 ; |
| write (deret[i], ' ' ); |
| end |
| else |
| begin |
| deret[i]:=deret[i- 1 ]+deret[i- 2 ]; |
| write (deret[i], ' ' ); |
| end ; |
| end ; |
| readln; |
| end . |
Program Jumlah Matriks Bahasa C
#include
<stdio.h>
#include
<stdlib.h>
int
A[3][3],B[3][3],C[3][3],i,j ;
int
main(int argc, char *argv[])
{
for(i=0;
i<3; i++)
{
for(j=0;j<3;j++)
{
printf
("Matriks A[%d][%d] : ", i+1, j+1);
scanf("%d",
&A[i][j]);
}
}
printf("===================================================\n");
for(i=0;
i<3; i++)
{
for(j=0;j<3;j++)
{
printf ("Matriks
B[%d][%d] : ", i+1, j+1);
scanf("%d",
&B[i][j]);
}
}
printf("\n
Matriks A \n");
printf("================\n");
for
(i=0; i<3;i++)
{
for (j=0; j<3;j++)
{
printf("|%3d",A[i][j]);
}
printf("\n");
}
printf("\n
Matriks B \n");
printf("================\n");
for (i=0; i<3;i++)
{
for
(j=0; j<3;j++)
{
printf("|%3d",B[i][j]);
}
printf("\n");
}
printf("===================================================\n");
printf
("Penjumlahan Matriks A + B : \n");
for(i=0;
i<3; i++)
{
for(j=0;j<3;j++)
{
C[i][j] =
A[i][j]+B[i][j];
}
}
for
(i=0; i<3;i++)
{
for
(j=0; j<3;j++)
{
printf("|%3d",C[i][j]);
}
printf("\n");
}
system("PAUSE");
return 0;
}
Thursday, 25 October 2012
Program Matrix Bahasa C
#include <stdio.h>
#include <stdlib.h>
int A[3][3],i,j ;
int main(int argc, char *argv[])
{
for(i=0; i<3; i++)
{
for(j=0;j<3;j++)
{
printf ("Matriks A[%d][%d] : ", i+1, j+1);
scanf("%d", &A[i][j]);
}
}
printf("\n Matriks A \n");
printf("================\n");
for (i=0; i<3;i++)
{
for (j=0; j<3;j++)
{
printf("|%3d",A[i][j]);
}
printf("\n");
}
system("PAUSE");
return 0;
}
#include <stdlib.h>
int A[3][3],i,j ;
int main(int argc, char *argv[])
{
for(i=0; i<3; i++)
{
for(j=0;j<3;j++)
{
printf ("Matriks A[%d][%d] : ", i+1, j+1);
scanf("%d", &A[i][j]);
}
}
printf("\n Matriks A \n");
printf("================\n");
for (i=0; i<3;i++)
{
for (j=0; j<3;j++)
{
printf("|%3d",A[i][j]);
}
printf("\n");
}
system("PAUSE");
return 0;
}
Wednesday, 24 October 2012
Program Hitung Gaji Karyawan Bahasa C
Disini kita belajar menggunakan input tipe data String dan Float.
#include <stdio.h>
#include <stdlib.h>
char nama[30];
char jabatan[30];
float gapok,tanak,tistri,gatot;
int main(int argc, char *argv[])
{
printf("MENGHITUNG GAJI \n");
printf("=========================== \n");
printf("Nama : "); fflush(stdin);
gets(nama);
printf("Jabatan : "); fflush(stdin);
gets(jabatan);
printf("Gaji Pokok : ");
scanf("%f",&gapok);
printf("T. anak : ");
scanf("%f",&tanak);
printf("T. istri : ");
scanf("%f",&tistri);
gatot = gapok+tanak+tistri;
printf("------------------------------------------\n");
printf("Nama : %s \n",nama);
printf("Jabatan : %s \n",jabatan);
printf("Gaji Total : Rp. %.2f \n",gatot);
system("PAUSE");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
char nama[30];
char jabatan[30];
float gapok,tanak,tistri,gatot;
int main(int argc, char *argv[])
{
printf("MENGHITUNG GAJI \n");
printf("=========================== \n");
printf("Nama : "); fflush(stdin);
gets(nama);
printf("Jabatan : "); fflush(stdin);
gets(jabatan);
printf("Gaji Pokok : ");
scanf("%f",&gapok);
printf("T. anak : ");
scanf("%f",&tanak);
printf("T. istri : ");
scanf("%f",&tistri);
gatot = gapok+tanak+tistri;
printf("------------------------------------------\n");
printf("Nama : %s \n",nama);
printf("Jabatan : %s \n",jabatan);
printf("Gaji Total : Rp. %.2f \n",gatot);
system("PAUSE");
return 0;
}
Program Menu Pilihan IF dalam IF Bahasa C
Ini contoh program untuk percabangan. Program Rental Kendaraan.
#include <stdio.h>
#include <stdlib.h>
float x;
int hrg;
int hari;
int tipe;
int main(int argc, char *argv[])
{
printf("HARGA RENTAL KENDARAAN \n");
printf("====================== \n");
printf("1. AVP \n");
printf("2. SEDAN \n");
printf("3. SUV \n");
printf("====================== \n");
printf ("Masukkan Nomor Jenis Kendaraan Yang Anda Pilih : "); scanf("%d",&tipe);
switch (tipe)
{
case 1:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================");
if (hari <= 3)
{
hrg = 500000;
x = hari * hrg;
printf("========================\n");
printf("Jenis Kendaraan : AVP\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 400000;
x = hari*hrg;
printf("Jenis Kendaraan : AVP\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
case 2:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================\n");
if (hari <= 3)
{
hrg = 600000;
x = hari*hrg;
printf("Jenis Kendaraan : SEDAN\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 450000;
x = hari*hrg;
printf("Jenis Kendaraan : SEDAN\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
case 3:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================\n");
if (hari <= 3)
{
hrg = 700000;
x = hari*hrg;
printf("Jenis Kendaraan : SUV\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 550000;
x = hari*hrg;
printf("Jenis Kendaraan : SUV\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
default:
{
printf("Jenis Kendaraan Salah(Pilih Nomor Menu Kendaraan)");
break;
}
}
system("PAUSE");
return 0;
}
++++Belajar lah saat anda bugar. dan berhentilah ketika anda lelah. BELAJAR++++
#include <stdio.h>
#include <stdlib.h>
float x;
int hrg;
int hari;
int tipe;
int main(int argc, char *argv[])
{
printf("HARGA RENTAL KENDARAAN \n");
printf("====================== \n");
printf("1. AVP \n");
printf("2. SEDAN \n");
printf("3. SUV \n");
printf("====================== \n");
printf ("Masukkan Nomor Jenis Kendaraan Yang Anda Pilih : "); scanf("%d",&tipe);
switch (tipe)
{
case 1:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================");
if (hari <= 3)
{
hrg = 500000;
x = hari * hrg;
printf("========================\n");
printf("Jenis Kendaraan : AVP\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 400000;
x = hari*hrg;
printf("Jenis Kendaraan : AVP\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
case 2:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================\n");
if (hari <= 3)
{
hrg = 600000;
x = hari*hrg;
printf("Jenis Kendaraan : SEDAN\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 450000;
x = hari*hrg;
printf("Jenis Kendaraan : SEDAN\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
case 3:
{
printf ("Lama Sewa : "); scanf("%d",&hari);
printf ("================================\n");
if (hari <= 3)
{
hrg = 700000;
x = hari*hrg;
printf("Jenis Kendaraan : SUV\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
else
{
hrg = 550000;
x = hari*hrg;
printf("Jenis Kendaraan : SUV\n", tipe);
printf("Lama Sewa : %d\n", hari);
printf("Harga Perhari : %d\n", hrg);
printf("Total : %.2f\n", x);
}
break;
}
default:
{
printf("Jenis Kendaraan Salah(Pilih Nomor Menu Kendaraan)");
break;
}
}
system("PAUSE");
return 0;
}
++++Belajar lah saat anda bugar. dan berhentilah ketika anda lelah. BELAJAR++++
Program input nama string Bahasa C
INI CONTOH PROGRAM DASAR PENGINPUTAN STRING :
#include <stdio.h>
#include <stdlib.h>
char nama_1[30];
char nama_2[30];
int main(int argc, char *argv[])
{
printf("Masukan nama 1 : "); fflush(stdin);
scanf("%s",&nama_1);
printf("Nama 1 yang diinputkan :%s\n",nama_1);
printf("--------------------------\n");
printf("Masukan nama 2:"); fflush(stdin);
gets(nama_2);
printf("Nama 2 yang amda masukan: %s",nama_2);
system("PAUSE");
return 0;
}
++++++++++++++BELAJAR + BELAJAR + BELAJAR ++++++++++++++++++++
#include <stdio.h>
#include <stdlib.h>
char nama_1[30];
char nama_2[30];
int main(int argc, char *argv[])
{
printf("Masukan nama 1 : "); fflush(stdin);
scanf("%s",&nama_1);
printf("Nama 1 yang diinputkan :%s\n",nama_1);
printf("--------------------------\n");
printf("Masukan nama 2:"); fflush(stdin);
gets(nama_2);
printf("Nama 2 yang amda masukan: %s",nama_2);
system("PAUSE");
return 0;
}
++++++++++++++BELAJAR + BELAJAR + BELAJAR ++++++++++++++++++++
Program Hitung Luas Lingkaran Bahasa C
#include <stdio.h>
#include <stdlib.h>
#define phi 3.14
float r,l;
int main(int argc, char *argv[])
{
printf (" masukan r : ") ; scanf (" %f ", &r);
l=phi*(r*r);
printf("Luas : %.2f \n",l);
system("PAUSE");
return 0;
}
#include <stdlib.h>
#define phi 3.14
float r,l;
int main(int argc, char *argv[])
{
printf (" masukan r : ") ; scanf (" %f ", &r);
l=phi*(r*r);
printf("Luas : %.2f \n",l);
system("PAUSE");
return 0;
}
Tuesday, 23 October 2012
Program Deret Angka Binary Tree Inorder Preorder Postorder (PASCAL)
Program Menyusun_Deretan_Angka_Dengan_Binary_Tree;
uses Crt;
type
PTR = ^Data;
Data = record
Info: Integer;
Leftson,Rightson: PTR;
end;
type
angkaa = array [1..100]of integer;
var
BinaryTree: PTR;
Menu : char;
Selesai : char;
Angka : integer;
{----------------------------------}
procedure InOrder(bt: PTR);
begin
if (bt <> nil) then
begin
InOrder(bt^.Leftson);
Write(bt^.Info:6);
InOrder(bt^.Rightson);
end;
end;
{----------------------------------}
procedure PreOrder(bt: PTR);
begin
if (bt <> nil) then
begin
Write(bt^.Info:6);
PreOrder(bt^.Leftson);
PreOrder(bt^.Rightson);
end;
end;
{----------------------------------}
procedure PostOrder(bt: PTR);
begin
if (bt <> nil) then
begin
PostOrder(bt^.Leftson);
PostOrder(bt^.Rightson);
Write(bt^.Info:6);
end;
end;
{----------------------------------}
Procedure Insert(var bt: PTR; Info: Integer);
var
Baru: PTR;
begin
if (bt = nil) then
begin
new(baru);
baru^.Info := Info;
baru^.Leftson := nil;
baru^.Rightson := nil;
bt := baru;
end
else
if (Info <= bt^.Info) then
Insert(bt^.Leftson, Info)
else
Insert(bt^.Rightson, Info);
end;
{----------------------------------}
procedure MenuUtama;
begin
WriteLn(' Menyusun_Deretan_Angka_Dengan_Binary_Tree ');
WriteLn('===============================================');
WriteLn;
WriteLn('1. Isi data!');
WriteLn('2. Tampilkan data secara In order');
WriteLn('3. Tampilkan data secara Pre order');
WriteLn('4. Tampilkan data secara Post order');
WriteLn('5. Keluar');
WriteLn;
Write('Silahkan pilih (1-5): ');
end;
{----------------------------------}
var i,n : integer;
begin
write('Masukkan Jumlah Data Deretan Angka! :');readln(n);
selesai:='N';
repeat
clrscr;
menuUtama;
readln(menu);
case menu of
'1' : begin
clrscr;
for i := 1 to n do
begin
write('input data ke ',i,' :');readln(angka);
insert(binarytree,angka);
end;
end;
'2' : begin
writeln;
Writeln('Tampilkan Deretan Angka Secara In Order');
writeln;
Writeln('=======================================');
writeln;
inorder(binarytree);
writeln;
end;
'3' :begin
writeln;
Writeln('Tampilkan Deretan Angka Secara Pre Order');
Writeln;
Writeln('========================================');
writeln;
preorder(binarytree);
writeln;
end;
'4' : begin
writeln;
Writeln('Tampilkan Deretan Angka Secara Post Order');
Writeln;
Writeln('========================================');
writeln;
postorder(binarytree);
writeln;
end;
'5' :begin
selesai:='Y';
end;
end;
readln;
until (selesai='Y') or (selesai='y');
end.
uses Crt;
type
PTR = ^Data;
Data = record
Info: Integer;
Leftson,Rightson: PTR;
end;
type
angkaa = array [1..100]of integer;
var
BinaryTree: PTR;
Menu : char;
Selesai : char;
Angka : integer;
{----------------------------------}
procedure InOrder(bt: PTR);
begin
if (bt <> nil) then
begin
InOrder(bt^.Leftson);
Write(bt^.Info:6);
InOrder(bt^.Rightson);
end;
end;
{----------------------------------}
procedure PreOrder(bt: PTR);
begin
if (bt <> nil) then
begin
Write(bt^.Info:6);
PreOrder(bt^.Leftson);
PreOrder(bt^.Rightson);
end;
end;
{----------------------------------}
procedure PostOrder(bt: PTR);
begin
if (bt <> nil) then
begin
PostOrder(bt^.Leftson);
PostOrder(bt^.Rightson);
Write(bt^.Info:6);
end;
end;
{----------------------------------}
Procedure Insert(var bt: PTR; Info: Integer);
var
Baru: PTR;
begin
if (bt = nil) then
begin
new(baru);
baru^.Info := Info;
baru^.Leftson := nil;
baru^.Rightson := nil;
bt := baru;
end
else
if (Info <= bt^.Info) then
Insert(bt^.Leftson, Info)
else
Insert(bt^.Rightson, Info);
end;
{----------------------------------}
procedure MenuUtama;
begin
WriteLn(' Menyusun_Deretan_Angka_Dengan_Binary_Tree ');
WriteLn('===============================================');
WriteLn;
WriteLn('1. Isi data!');
WriteLn('2. Tampilkan data secara In order');
WriteLn('3. Tampilkan data secara Pre order');
WriteLn('4. Tampilkan data secara Post order');
WriteLn('5. Keluar');
WriteLn;
Write('Silahkan pilih (1-5): ');
end;
{----------------------------------}
var i,n : integer;
begin
write('Masukkan Jumlah Data Deretan Angka! :');readln(n);
selesai:='N';
repeat
clrscr;
menuUtama;
readln(menu);
case menu of
'1' : begin
clrscr;
for i := 1 to n do
begin
write('input data ke ',i,' :');readln(angka);
insert(binarytree,angka);
end;
end;
'2' : begin
writeln;
Writeln('Tampilkan Deretan Angka Secara In Order');
writeln;
Writeln('=======================================');
writeln;
inorder(binarytree);
writeln;
end;
'3' :begin
writeln;
Writeln('Tampilkan Deretan Angka Secara Pre Order');
Writeln;
Writeln('========================================');
writeln;
preorder(binarytree);
writeln;
end;
'4' : begin
writeln;
Writeln('Tampilkan Deretan Angka Secara Post Order');
Writeln;
Writeln('========================================');
writeln;
postorder(binarytree);
writeln;
end;
'5' :begin
selesai:='Y';
end;
end;
readln;
until (selesai='Y') or (selesai='y');
end.
Subscribe to:
Posts (Atom)