#include<conio.h>
#include<stdio.h>
#include<iostream.h>
main(){
int a[50],jml;
cout<<"Masukkan jumlah data : ";
cin>>jml;
for (int i=0;i<jml;i++){
cout<<"Masukkan angka "<<i+1<<" : ";
cin>>a[i];
}
int x;
for (int i=0;i<jml-1;i++)
for (int j=i+1;j<jml;j++){
if (a[i]>a[j]){
x=a[i];
a[i]=a[j];
a[j]=x;
}
}
for (int i=0;i<jml;i++){
cout<<a[i]<<" ";
}
getche();//header conio.h
}
#include<stdio.h>
#include<iostream.h>
main(){
int a[50],jml;
cout<<"Masukkan jumlah data : ";
cin>>jml;
for (int i=0;i<jml;i++){
cout<<"Masukkan angka "<<i+1<<" : ";
cin>>a[i];
}
int x;
for (int i=0;i<jml-1;i++)
for (int j=i+1;j<jml;j++){
if (a[i]>a[j]){
x=a[i];
a[i]=a[j];
a[j]=x;
}
}
for (int i=0;i<jml;i++){
cout<<a[i]<<" ";
}
getche();//header conio.h
}
No comments:
Post a Comment