24 Juni 2009

Program C++ Selection Sort 1

24 Juni 2009
#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 firstelement, temp;

//Some input
for (i = 0; i < length; i++)
{
cout << "Enter a number: ";
cin >> array[i];
}

//Algorithm
for (i= length - 1; i > 0; i--)
{
firstelement = 0;
for (j=1; j<=i; j++)
{
if (array[j] < array[firstelement])
firstelement = j;
}
temp = array[firstelement];
array[firstelement] = array[i];
array[i] = temp;
}

//Some output
for (i = 0; i < 5; i++)
{
cout << array[i] << endl;
}
getch();
}

program setelah di eksekusi:


2 comments:

rivan mengatakan...

gan, kok pakenya include
apa bedanya kalo pake include ??

rivan mengatakan...

gan, kok pakenya include
apa bedanya kalo pake include ??

Poskan Komentar

sampaikan komentar dengan sopan dan bertanggung jawab :)