Praktikum PAA D n C


dnc

listing algoritma divide and conquer dengan menggunakan c++
#include
#include

int max,min;
int a[100];

void maxmin(int i, int j)
{
int max1,min1,mid;
if (i==j)
max=min=a[i];
else
if (i==j-1)
{
if (a[i]<a[j])
{
max=a[j];
min=a[i];
}
else
{
max=a[i];
min=a[j];
}
}
else
{
mid=(i+j)/2;
maxmin(i,mid);
max1=max;
min1=min;
maxmin(mid+1,j);
if(maxmin1)
min=min1;
}
}

void main()
{
int i,num;
clrscr();
printf(“\n\t\t\tMAXIMUM & MINIMUM\n\n”);
printf(“\nmasukkan banyak angka:”);
scanf(“%d”,&num);
printf(“masukkan angkanya:\n”);
for (i=1;i<=num;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
min=a[0];
maxmin(1,num);
printf("Maximum angka:%d\n",max);
printf("Minimum angka:%d\n",min);
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: