LAPORAN PRAKTIKUM 4
Disusn Oleh :
Riski Yoga Kusumadya
201101019
Dosen :
Yosef Murya Kusuma Ardhana, S.T
JURUSAN SISTEM INFORMASI
SEKOLAH TINGGI ILMU KOMPUTER (STIKom)
"YOS SUDARSO"
PURWOKERTO
2012
//============================================================================
// Name : 1.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main()
{
int i, j, imin;
int n, urut;
int tmp;
int arr[50];
cout<<"input data yang akan di urutkan :";
cin>>n;
urut=1;
for(i=0;i<n;i++){
cout<<"masukkan data ke "<<i+1<<" :";
cin>>arr[i];
}
for(i=0;i<n-1;i++){
imin=1;
for(j=urut;j<n;j++){
if(arr[i]<arr[imin]){
imin=j;
if(arr[i]!=arr[imin]){
tmp=arr[i];
if(arr[i]>arr[imin]){
arr[i]=arr[imin];
arr[imin]=tmp;
}
}
}
}
urut=urut+1;
}
cout<<"setelah pengurutan\n";
for(i=0;i<n;i++)
{
cout<<"elemen ke "<<i+1<<":"<<arr[i]<<"\n";
}
return 0;
}
Listing Program 4.1
// Name : 1.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main()
{
int i, j, imin;
int n, urut;
int tmp;
int arr[50];
cout<<"input data yang akan di urutkan :";
cin>>n;
urut=1;
for(i=0;i<n;i++){
cout<<"masukkan data ke "<<i+1<<" :";
cin>>arr[i];
}
for(i=0;i<n-1;i++){
imin=1;
for(j=urut;j<n;j++){
if(arr[i]<arr[imin]){
imin=j;
if(arr[i]!=arr[imin]){
tmp=arr[i];
if(arr[i]>arr[imin]){
arr[i]=arr[imin];
arr[imin]=tmp;
}
}
}
}
urut=urut+1;
}
cout<<"setelah pengurutan\n";
for(i=0;i<n;i++)
{
cout<<"elemen ke "<<i+1<<":"<<arr[i]<<"\n";
}
return 0;
}
Output Program
Listing Program 4.2
//============================================================================
// Name : 2.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main(){
int i,j,n;
int Tmp;
int Arr[50];
cout<<"inputkan banyak data yang akan diurutkan :";
cin>>n;
for(i=0;i<n;i++){
cout<<"masukkan data ke "<<i+1<<":";
cin>>Arr[i];
for(j=0;j<n-1;j++){
if(Arr[j]>Arr[j+1]){
Tmp=Arr[j];
Arr[j]=Arr[j+1];
Arr[j+1]=Tmp;
}
}
}
cout<<"\nsetelah Pengurutan\n";
for(i=0;i<n;i++){
cout<<"Elemen ke"<<" :"<<i+1<<Arr[i]<<"\n";
}
return 0;
}
Output Program
Tidak ada komentar:
Posting Komentar