Pages

Senin, 16 Januari 2012

PENGURUTAN [TUGAS]


#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void main(){
int x,i;
int data[100];
cout <<" banyak data : "; cin>>x;

for (i=1; i<=x; i++){
cout<<" data ke-"<<i<<" : "; cin>>data[i];
clrscr();
}

cout<<" sebelum diurutkan : "<<endl;
for (i=1; i<=x; i++){
cout<<"  "<<data[i];
}

int temp,a;
for (i=2; i<=x; i++){
for (a=x; a>=i; a--){
if (data[a] < data[a-1]){
temp=data[a];
data[a]=data[a-1];
data[a-1]=temp;
}
}
}
cout<<"\n sesudah diurutkan : "<<endl;
for (i=1; i<=x; i++){
cout<<"  "<<data[i];
}
getch();
} Print Friendly and PDF

Artikel Terkait:

0 komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...