// Program mengurutkan dengan menggunakan
// teknik bubble sort.
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int array[100],n,c,d,temp;
printf("Masukkan jumlah data yang masih acak\n");
printf("\n");
scanf("%d",&n);
printf("\n");
printf("Masukkan ke-%d data acak tersebut\n",n);
printf("\n");
for(c=0;c<n;c++)
scanf("%d",&array[c]);
for(c=0;c<(n-1);c++)
{
for(d=0;d<n-c-1;d++)
{
if(array[d]>array[d+1])
{
temp=array[d];
array[d]=array[d+1];
array[d+1]=temp;
}
}
}
printf("\n");
printf("Data setelah diurutkan\n");
printf("\n");
for(c=0;c<n;c++)
printf("%d\n",array[c]);
return 0;
}
Jumat, 29 November 2013
Pemrograman C Untuk Mematikan Komputer
//Program untuk mematikan komputer
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char ch;
printf("Anda hendak mematikan komputer sekarang? (Y/N)\n");
scanf("%ch",ch);
if (ch=='y'||ch=='Y')
system("C:\\WINDOWS\\System32\\shutdown -s");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char ch;
printf("Anda hendak mematikan komputer sekarang? (Y/N)\n");
scanf("%ch",ch);
if (ch=='y'||ch=='Y')
system("C:\\WINDOWS\\System32\\shutdown -s");
return 0;
}
Kamis, 28 November 2013
Operator Relasi Dan Operator Logika Bahasa Pemrograman C
1. Operator Relasi
> Lebih dari
>= Lebih dari atau sama dengan
< Kurang dari
<= Kurang dari atau sama dengan
== Sama dengan
!= Tidak sama dengan
2. Operator Logika
&& Dan
|| Atau
! Tidak
> Lebih dari
>= Lebih dari atau sama dengan
< Kurang dari
<= Kurang dari atau sama dengan
== Sama dengan
!= Tidak sama dengan
2. Operator Logika
&& Dan
|| Atau
! Tidak
Langkah - Langkah Dalam Perencanaan
Langkah - langkah pokok dalam membuat suatu rencana adalah sebagai berikut:
- Menentukan tujuan yang akan dicapai. Tujuan tersebut harus jelas (singkat & padat), mungkin dicapai (tidak terlalu berat atau muluk-muluk), serta tidak terlalu ringan.
- Menentukan keadaan perusahaan dalam kaitannya dengan tujuan yang hendak dicapai. Hal ini dapat juga berarti menentukan tujuan-tujuan antara atau sub tujuan yang akan menopang pencapaian tujuan utama tersebut.
- Menentukan faktor-faktor yang mendukung dan yang menghambat tercapainya tujuan tersebut.
- Merumuskan kegiatan yang harus dilaksanakan.
Senin, 25 November 2013
Script Initial Configuration Mikrotik
#| ether1 is renamed to ether1-gateway
#| DHCP client and masquerade is set on ether1-gateway
#| ether2 is renamed to ether2-master-local and configured as switch master port for ether3-ether5
#| IP address 192.168.88.1/24 and DHCP server is set on ether2-master interface
#| DHCP servers address pool is 192.168.88.10-192.168.88.254
:global action;
:local dhcpEnabled 0;
:local wirelessEnabled 0;
#check for wireless and dhcp packages
:if ([:len [/system package find name="dhcp" !disabled]] != 0) do={
:set dhcpEnabled 1;
}
:if ([:len [/system package find name="wireless" !disabled]] != 0) do={
:set wirelessEnabled 1;
}
#-------------------------------------------------------------------------------
# Apply configuration.
# these commands are executed after installation or configuration reset
#-------------------------------------------------------------------------------
:if ($action = "apply") do={
# wait for interfaces
:while ([/interface ethernet find] = "") do={ :delay 1s; };
/interface set ether1 name="ether1-gateway";
:if ( $dhcpEnabled = 1) do={
/ip dhcp-client add interface=ether1-gateway disabled=no comment="default configuration";
}
/interface {
set ether2 name=ether2-master-local;
set ether3 name=ether3-slave-local;
set ether4 name=ether4-slave-local;
set ether5 name=ether5-slave-local;
}
/interface ethernet {
set ether3-slave-local master-port=ether2-master-local;
set ether4-slave-local master-port=ether2-master-local;
set ether5-slave-local master-port=ether2-master-local;
}
/ip address add address=192.168.88.1/24 interface=ether2-master-local comment="default configuration";
:if ($dhcpEnabled = 1) do={
/ip pool add name="default-dhcp" ranges=192.168.88.10-192.168.88.254;
/ip dhcp-server
add name=default address-pool="default-dhcp" interface=ether2-master-local disabled=no;
/ip dhcp-server network
add address=192.168.88.0/24 gateway=192.168.88.1 dns-server=192.168.88.1 comment="default configuration";
}
/ip firewall nat add chain=srcnat out-interface=ether1-gateway action=masquerade comment="default configuration"
/ip dns {
set allow-remote-requests=yes
static add name=router address=192.168.88.1
}
}
#-------------------------------------------------------------------------------
# Revert configuration.
# these commands are executed if user requests to remove default configuration
#-------------------------------------------------------------------------------
:if ($action = "revert") do={
:if ($dhcpEnabled = 1) do={
:local o [/ip dhcp-server network find comment="default configuration"]
:if ([:len $o] != 0) do={ /ip dhcp-server network remove $o }
:local o [/ip dhcp-server find name="default" address-pool="default-dhcp" interface="ether2-master-local" !disabled]
:if ([:len $o] != 0) do={ /ip dhcp-server remove $o }
/ip pool {
:local o [find name="default-dhcp" ranges=192.168.88.10-192.168.88.254]
:if ([:len $o] != 0) do={ remove $o }
}
:local o [/ip dhcp-client find comment="default configuration"]
:if ([:len $o] != 0) do={ /ip dhcp-client remove $o }
}
/ip dns {
set allow-remote-requests=no
:local o [static find name=router address=192.168.88.1]
:if ([:len $o] != 0) do={ static remove $o }
}
/ip address {
:local o [find comment="default configuration"]
:if ([:len $o] != 0) do={ remove $o }
}
# remove switch
/interface set ether2-master-local name=ether2;
/interface ethernet set ether3-slave-local master-port=none;
/interface set ether3-slave-local name=ether3;
/interface ethernet set ether4-slave-local master-port=none;
/interface set ether4-slave-local name=ether4;
/interface ethernet set ether5-slave-local master-port=none;
/interface set ether5-slave-local name=ether5;
}
#| DHCP client and masquerade is set on ether1-gateway
#| ether2 is renamed to ether2-master-local and configured as switch master port for ether3-ether5
#| IP address 192.168.88.1/24 and DHCP server is set on ether2-master interface
#| DHCP servers address pool is 192.168.88.10-192.168.88.254
:global action;
:local dhcpEnabled 0;
:local wirelessEnabled 0;
#check for wireless and dhcp packages
:if ([:len [/system package find name="dhcp" !disabled]] != 0) do={
:set dhcpEnabled 1;
}
:if ([:len [/system package find name="wireless" !disabled]] != 0) do={
:set wirelessEnabled 1;
}
#-------------------------------------------------------------------------------
# Apply configuration.
# these commands are executed after installation or configuration reset
#-------------------------------------------------------------------------------
:if ($action = "apply") do={
# wait for interfaces
:while ([/interface ethernet find] = "") do={ :delay 1s; };
/interface set ether1 name="ether1-gateway";
:if ( $dhcpEnabled = 1) do={
/ip dhcp-client add interface=ether1-gateway disabled=no comment="default configuration";
}
/interface {
set ether2 name=ether2-master-local;
set ether3 name=ether3-slave-local;
set ether4 name=ether4-slave-local;
set ether5 name=ether5-slave-local;
}
/interface ethernet {
set ether3-slave-local master-port=ether2-master-local;
set ether4-slave-local master-port=ether2-master-local;
set ether5-slave-local master-port=ether2-master-local;
}
/ip address add address=192.168.88.1/24 interface=ether2-master-local comment="default configuration";
:if ($dhcpEnabled = 1) do={
/ip pool add name="default-dhcp" ranges=192.168.88.10-192.168.88.254;
/ip dhcp-server
add name=default address-pool="default-dhcp" interface=ether2-master-local disabled=no;
/ip dhcp-server network
add address=192.168.88.0/24 gateway=192.168.88.1 dns-server=192.168.88.1 comment="default configuration";
}
/ip firewall nat add chain=srcnat out-interface=ether1-gateway action=masquerade comment="default configuration"
/ip dns {
set allow-remote-requests=yes
static add name=router address=192.168.88.1
}
}
#-------------------------------------------------------------------------------
# Revert configuration.
# these commands are executed if user requests to remove default configuration
#-------------------------------------------------------------------------------
:if ($action = "revert") do={
:if ($dhcpEnabled = 1) do={
:local o [/ip dhcp-server network find comment="default configuration"]
:if ([:len $o] != 0) do={ /ip dhcp-server network remove $o }
:local o [/ip dhcp-server find name="default" address-pool="default-dhcp" interface="ether2-master-local" !disabled]
:if ([:len $o] != 0) do={ /ip dhcp-server remove $o }
/ip pool {
:local o [find name="default-dhcp" ranges=192.168.88.10-192.168.88.254]
:if ([:len $o] != 0) do={ remove $o }
}
:local o [/ip dhcp-client find comment="default configuration"]
:if ([:len $o] != 0) do={ /ip dhcp-client remove $o }
}
/ip dns {
set allow-remote-requests=no
:local o [static find name=router address=192.168.88.1]
:if ([:len $o] != 0) do={ static remove $o }
}
/ip address {
:local o [find comment="default configuration"]
:if ([:len $o] != 0) do={ remove $o }
}
# remove switch
/interface set ether2-master-local name=ether2;
/interface ethernet set ether3-slave-local master-port=none;
/interface set ether3-slave-local name=ether3;
/interface ethernet set ether4-slave-local master-port=none;
/interface set ether4-slave-local name=ether4;
/interface ethernet set ether5-slave-local master-port=none;
/interface set ether5-slave-local name=ether5;
}
Minggu, 24 November 2013
Progress Bar Visual Basic 6.0
Private Sub Cmd_Rekam_Click()
Dim i As Integer, j(32766) As String
Me.Prog_Bar.Min = LBound(j)
Me.Prog_Bar.Max = UBound(j)
Me.Prog_Bar.Visible = True
For i = LBound(j) To UBound(j)
Me.Prog_Bar.Value = i
Next i
Me.Prog_Bar.Visible = False
End Sub
Private Sub Form_Load()
Me.Prog_Bar.Visible = False
End Sub
Dim i As Integer, j(32766) As String
Me.Prog_Bar.Min = LBound(j)
Me.Prog_Bar.Max = UBound(j)
Me.Prog_Bar.Visible = True
For i = LBound(j) To UBound(j)
Me.Prog_Bar.Value = i
Next i
Me.Prog_Bar.Visible = False
End Sub
Private Sub Form_Load()
Me.Prog_Bar.Visible = False
End Sub
Jumat, 22 November 2013
Pemrograman C, Untuk Sorting Data
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int data[10],data2[10];
int n;
void tukar(int a,int b){
int t;
t = data[b];
data[b] = data[a];
data[a] = t;
}
void bubble_sort(){
int i;
for(i=1;i<n;i++){
int j;
for(j=n-1;j>=i;j--){
if(data[j]<data[j-1]) tukar(j,j-1);
}
}
printf("bubble sort selesai!\n");
}
void exchange_sort(){
int i;
for (i=0; i<n-1; i++){
int j;
for(j = (i+1); j<n; j++){
if (data [i] > data[j]) tukar(i,j);
}
}
printf("exchange sort selesai!\n");
}
void selection_sort(){
int pos,i,j;
for(i=0;i<n-1;i++){
pos = i;
for(j = i+1;j<n;j++){
if(data[j] < data[pos]) pos = j;
}
if(pos != i) tukar(pos,i);
}
printf("selection sort selesai!\n");
}
void insertion_sort(){
int temp,i,j;
for(i=1;i<n;i++){
temp = data[i];
j = i -1;
while(data[j]>temp && j>=0){
data[j+1] = data[j];
j--;
}
data[j+1] = temp;
}
printf("insertion sort selesai!\n");
}
void Input(){
printf("Masukkan jumlah data = ");scanf("%d",&n);
int i;
for(i=0;i<n;i++){
printf("Masukkan data ke-%d = ",(i+1));scanf("%d",&data[i]);
data2[i] = data[i];
}
}
void AcakLagi(){
int i;
for(i=0;i<n;i++){
data[i] = data2[i];
}
printf("Data sudah teracak!\n");
}
void Tampil(){
printf("Data : ");
int i;
for(i=0;i<n;i++){
printf("%d ",data[i]);
}
printf("\n");
}
int main(int argc, char *argv[]) {
int pil;
do{
printf("1. Input Data\n");
printf("2. Bubble Sort\n");
printf("3. Exchange Sort\n");
printf("4. Selection Sort\n");
printf("5. Tampilkan Data\n");
printf("6. Acak\n");
printf("7. Exit\n");
printf("Pilihan = ");scanf("%d",&pil);
switch(pil){
case 1:Input();break;
case 2:bubble_sort();break;
case 3:exchange_sort();break;
case 4:selection_sort();break;
case 5:Tampil();break;
case 6:AcakLagi();break;
}
getch();
}while(pil!=7);
return 0;
}
#include <stdlib.h>
#include <conio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int data[10],data2[10];
int n;
void tukar(int a,int b){
int t;
t = data[b];
data[b] = data[a];
data[a] = t;
}
void bubble_sort(){
int i;
for(i=1;i<n;i++){
int j;
for(j=n-1;j>=i;j--){
if(data[j]<data[j-1]) tukar(j,j-1);
}
}
printf("bubble sort selesai!\n");
}
void exchange_sort(){
int i;
for (i=0; i<n-1; i++){
int j;
for(j = (i+1); j<n; j++){
if (data [i] > data[j]) tukar(i,j);
}
}
printf("exchange sort selesai!\n");
}
void selection_sort(){
int pos,i,j;
for(i=0;i<n-1;i++){
pos = i;
for(j = i+1;j<n;j++){
if(data[j] < data[pos]) pos = j;
}
if(pos != i) tukar(pos,i);
}
printf("selection sort selesai!\n");
}
void insertion_sort(){
int temp,i,j;
for(i=1;i<n;i++){
temp = data[i];
j = i -1;
while(data[j]>temp && j>=0){
data[j+1] = data[j];
j--;
}
data[j+1] = temp;
}
printf("insertion sort selesai!\n");
}
void Input(){
printf("Masukkan jumlah data = ");scanf("%d",&n);
int i;
for(i=0;i<n;i++){
printf("Masukkan data ke-%d = ",(i+1));scanf("%d",&data[i]);
data2[i] = data[i];
}
}
void AcakLagi(){
int i;
for(i=0;i<n;i++){
data[i] = data2[i];
}
printf("Data sudah teracak!\n");
}
void Tampil(){
printf("Data : ");
int i;
for(i=0;i<n;i++){
printf("%d ",data[i]);
}
printf("\n");
}
int main(int argc, char *argv[]) {
int pil;
do{
printf("1. Input Data\n");
printf("2. Bubble Sort\n");
printf("3. Exchange Sort\n");
printf("4. Selection Sort\n");
printf("5. Tampilkan Data\n");
printf("6. Acak\n");
printf("7. Exit\n");
printf("Pilihan = ");scanf("%d",&pil);
switch(pil){
case 1:Input();break;
case 2:bubble_sort();break;
case 3:exchange_sort();break;
case 4:selection_sort();break;
case 5:Tampil();break;
case 6:AcakLagi();break;
}
getch();
}while(pil!=7);
return 0;
}
Kamis, 21 November 2013
Pemrograman C, Membuat Piramida
//Program untuk membuat piramida
#include<stdio.h>
main()
{
int baris,c,n,temp;
printf("Masukkan jumlah baris dari piramida bintang yang diinginkan : ");
scanf ("%d",&n);
temp=n;
for(baris=1;baris<=n;baris++)
{
for(c=1;c<temp;c++)
printf(" ");
temp--;
for(c=1;c<=2*baris-1;c++)
printf("*");
printf("\n");
}
return 0;
}
#include<stdio.h>
main()
{
int baris,c,n,temp;
printf("Masukkan jumlah baris dari piramida bintang yang diinginkan : ");
scanf ("%d",&n);
temp=n;
for(baris=1;baris<=n;baris++)
{
for(c=1;c<temp;c++)
printf(" ");
temp--;
for(c=1;c<=2*baris-1;c++)
printf("*");
printf("\n");
}
return 0;
}
Minggu, 10 November 2013
Selection Sort
- Mengurutkan sejumlah data dari yang terkecil ke terbesar
Data yang masih acak --> 4 3 7 9 10 2
Proses 1
[0] [1] [2] [3] [4] [5]
4 3 7 9 10 2
Pembanding Posisi
4 > 3 (tukar idx) 1
3 < 7 1
3 < 9 1
3 < 10 1
3 > 2 (tukar idx) 5
Tukar data ke-0 (4) dengan data ke-5 (2)
[0] [1] [2] [3] [4] [5]
2 3 7 9 10 4
Proses 2
[0] [1] [2] [3] [4] [5]
2 3 7 9 10 4
Pembanding Posisi
3 < 7 1
3 < 9 1
3 < 10 1
3 < 10 1
3 < 4 1
Tukar data ke-1 (3) dengan data ke-1 (3)
[0] [1] [2] [3] [4] [5]
2 3 7 9 10 4
Proses 3
[0] [1] [2] [3] [4] [5]
2 3 7 9 10 4
Pembanding Posisi
7 < 9 2
7 < 10 2
7 > 4 (tukar idx) 5
Tukar data ke-2 (7) dengan data ke-5 (4)
[0] [1] [2] [3] [4] [5]
2 3 4 9 10 7
Proses 4
[0] [1] [2] [3] [4] [5]
2 3 4 9 10 7
Pembanding Posisi
9 < 10 3
9 > 7 (tukar idx) 5
Tukar data ke-3 (9) dengan data ke-5 (7)
[0] [1] [2] [3] [4] [5]
2 3 4 7 10 9
Proses 5
[0] [1] [2] [3] [4] [5]
2 3 4 7 10 9
Pembanding Posisi
10 > 9 (tukar idx) 5
Tukar data ke-4 (10) dengan data ke-5 (9)
[0] [1] [2] [3] [4] [5]
2 3 4 7 9 10
- Mengurutkan sejumlah data dari yang terbesar ke terkecil
Data yang masih acak --> 4 3 7 9 10 2
Proses 1
[0] [1] [2] [3] [4] [5]
4 3 7 9 10 2
Pembanding Posisi
4 > 3 0
4 < 7 (tukar idx) 2
7 < 9 (tukar idx) 3
9 < 10 (tukar idx) 4
10 > 2 4
Tukar data ke-0 (4) dengan data ke-4 (10)
[0] [1] [2] [3] [4] [5]
10 3 7 9 4 2
Proses 2
[0] [1] [2] [3] [4] [5]
10 3 7 9 4 2
Pembanding Posisi
3 < 7 (tukar idx) 2
7 < 9 (tukar idx) 3
9 > 4 3
9 > 2 3
Tukar data ke-1(3) dengan data ke-3 (9)
[0] [1] [2] [3] [4] [5]
10 9 7 3 4 2
Proses 3
[0] [1] [2] [3] [4] [5]
10 9 7 3 4 2
Pembanding Posisi
7 > 3 2
7 > 4 2
7 > 2 2
Tukar data ke-2(7) dengan data ke-2 (7)
[0] [1] [2] [3] [4] [5]
10 9 7 3 4 2
Proses 4
[0] [1] [2] [3] [4] [5]
10 9 7 3 4 2
Pembanding Posisi
3 < 4 (tukar idx) 4
4 > 2 4
Tukar data ke-3(3) dengan data ke-4 (4)
[0] [1] [2] [3] [4] [5]
10 9 7 4 3 2
Proses 5
[0] [1] [2] [3] [4] [5]
10 9 7 4 3 2
Pembanding Posisi
3 > 2 4
Tukar data ke-4(3) dengan data ke-4 (3)
[0] [1] [2] [3] [4] [5]
10 9 7 4 3 2
Langganan:
Postingan (Atom)