include
include
int jum, mxb,
mnb;
int tab[10];
void input()
{
int i;
printf("Masukkan jumlah :
");
scanf("%d",&jum);
for(i = 1; i <=jum;i++)
{
printf("angka ke-%d : ",i);
scanf("%d",&tab[i]);
}
}
int cekmx(int
tb[10], int a, int b)
{
int k, max1,
max2;
if(a==b)
{
mxb=tb[a];
}
else
{
if(a==b - 1)
{
if(tb[a]
mxb = tb[b];
else
mxb=tb[a];
}
else
{
k=(a+b)/2;
max1=cekmx(tb,a,k);
max2=cekmx(tb,k+1,b);
if(max1
mxb=max2;
else
mxb=max1;
}
}
return mxb;
}
int cekmn(int
tb[10], int a, int b)
{
int q, mn1, mn2;
if(a==b)
{
mnb=tb[a];
}
else
{
if(a==b-1)
{
if(tb[a]
mnb=tb[a];
else
mnb=tb[b];
}
else
{
q=(a+b)/2;
mn1=cekmn(tb,a,q);
mn2=cekmn(tb,q+1,b);
if(mn1
mnb=mn1;
else
mnb=mn2;
}
}
return mnb;
}
main ()
{
clrscr();
input();
printf("\n");
printf("max=%d\n",cekmx(tab,1,jum));
printf("min=%d\n",cekmn(tab,1,jum));
getch();
}setelah kita compile di turbo C maka akan menampilkan output seperti berikut
Tidak ada komentar:
Posting Komentar