Tuesday, 20 May 2014

Mencari nilai minmax

#include <cstdlib>
#include <iostream>

using namespace std;
void MinMaks2(int A[],int i,int j,int k,int min, int maks){
int min1,min2,maks1,maks2;

if(i==j){
min=A[i];
maks=A[i];
}
else if(i==j-1){
if (A[i]<A[i]){
maks=A[j];
min=A[i];
}
}
else{
maks=A[i];
maks=A[j];
}
}
else {
k =(i+j)/2;
MinMaks2(A, i, k, min1, maks1);
MinMaks2(A, k+1, j, min2, maks2);

if(min1 < min2){
min = min1;
}
else {
min = min2;

if(maks1 < maks2);
maks = maks1;
else {
maks = maks2;
}
}

int main(int argc, char *argv[])
{
int data[] = {3,6,1,20,8,19,2,4};
int min, maks;
int i = 0;
int j = 7;
MinMaks2(data, i,j, min, maks);
cout << "Nilai min = " << min << endl;
cout << "Nilai maks = " << maks <<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Agus
 

No comments:

Post a Comment

Konversi Suhu

#include <iostream> #include <conio.h> //#include <cstdlib> //#include <iostream.h> void main( float Celcius, Kelvi...