You are on page 1of 2

#include <stdio.

h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
#include <graphics.h>
void main()
{
clrscr();
int data[15]={15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
int cnt,temp,panjang_data,posisi_data,x,cnzt=0;

selection:
cnt=0;
do
{
printf("%i ",data[cnt]);
cnt++;
}while(cnt!=sizeof(data)/2);
printf("\n");
panjang_data=sizeof(data)/2-1;//9

a:
temp=data[0];
for(x=0;x<panjang_data;x++)
{
if(temp<data[x+1])
{
temp=data[x+1];
posisi_data=x+1;
cnzt++;
}
else
{
if(temp==data[x+1])
{
temp=data[x+1];
}
else if(x==0)
{
temp=0;
}
else
{

}
}

if(temp==0)
{
temp=data[panjang_data];
data[panjang_data]=data[0];
data[0]=temp;
panjang_data=sizeof(data)/2-1;
}
else
{
data[posisi_data]=data[panjang_data];
data[panjang_data]=temp;
panjang_data--;
}

if(panjang_data==0)
{
printf("\n");
cnt=0;
do
{
printf("%i ",data[cnt]);
cnt++;
}while(cnt!=sizeof(data)/2);
printf("\n%i",cnzt);

getch();
exit(1);
}
else
{
goto a;
}
}

You might also like