24 Juni 2009

Program C++ Exchange Sort 1

24 Juni 2009
//contoh pemograman exchange sort
#include <iostream>
#include <conio.h>

int main(void)
{
int array[5]; // An array of integers.
int length = 5; // Lenght of the array.
int i, j;
int temp;

//Some input
for (i = 0; i < 5; i++)
{
cout << "Masukan angka: ";
cin >> array[i];
}

//Algorithm
for(i = 0; i < (length -1); i++)
{

for (j=(i + 1); j < length; j++)
{
if (array[i] < array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
//Some output
for (i = 0; i < 5; i++)
{
cout<<endl;
cout<<array[i]<< " ";
}
getch();
}



program setelah di eksekusi:

0 comments:

Poskan Komentar

sampaikan komentar dengan sopan dan bertanggung jawab :)