Pertemuan ke-6, Kasus 6.4

Algoritma untuk menentukan nilai maksimum dan minimum dari n bilangan.

Algoritma :
Deklarasi : integer i;
Deskripsi : m1=data[1]
        m2=data[1]
        for i=2 tod n do;
        if(data[i]>m1)then m1=data[i];
        if(data[i]<m2)then m2=data[i];
        endfor;

Flowchart :


Program Dev C++ :
#include <iostream>
#include <cstdlib>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

class maxmin
  {    
   public:           
          maxmin();           
          int proses(int n,int max,int min,int jumlah);       
   private:            
          int n, max, min, jumlah, x;
  };

maxmin::maxmin()
{
  cout<<"\tMenampilkan Maximum, Minimum, dan Jumlah Sejumlah n Bilangan "<<endl;
  cout<<endl;
}

int maxmin::proses(int n, int max, int min, int jumlah)
{
if(n==0){
   cout<<endl;
   cout<<" NILAI MAKSIMUM       : "<<max<<endl;
   cout<<" NILAI MINIMUM        : "<<min<<endl;
   cout<<" JUMLAH SELURUH DERET : "<<jumlah<<endl<<endl;
   return 0;
  }  

else{
   cout<<" Masukkan Bilangan : ";cin>>x;
      jumlah+=x;

   if(x<min)
   {
      min=x;
   }       

   if(x>max)
   {
      max=x;
   }
    return proses(n-1,max,min,jumlah);
 }  
}

int main(int argc, char *argv[]){
    maxmin x;
    x.proses(5,1,1,0);
  
    system("PAUSE");
  
    return EXIT_SUCCESS;
}

Sekian dan Terima Kasih, Semoga Bermanfaat.

Comments

Popular posts from this blog

Program Menghitung Hambatan Seri dan Pararel

Menghitung nilai ipk mahasiswa

Contoh Class Dalam Bahasa C++ (Program dan Penjelasan)