C++ PROGRAM BILANGAN (terbesar, terkecil, rerata)

C++ PROGRAM BILANGAN (terbesar, terkecil, rerata)

#include <iostream>

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

int main(int argc, char *argv[]) {

int bil, total, trbesar, trkecil, rata, i, n;
total=0;

cout<<"==================================\n";
cout<<"| <<<<<< PROGRAM BILANGAN >>>>>> |\n";
cout<<"==================================\n\n";
cout<<"Masukkan banyaknya bilangan : "; cin>>n;
for(i=1; i<=n; i++){
cout<<"Masukkan bilangan : "; cin>>bil;
total=total+bil;
rata=total/n;
if(i==1){
trbesar=bil;
trkecil=bil;
}
else if(trkecil>bil){
trkecil=bil;
}
else if (trbesar<bil){

trbesar=bil;
}
else { }

}

cout<<"Jumlah Bilangan = "<<total<<endl;
cout<<"Rata-rata = "<<rata;
cout<<"\nBilangan Terbesar = "<<trbesar;
cout<<"\nBilangan Terkecil = "<<trkecil;

return 0;
}

HASIL COMPILE :





Posting Komentar

0 Komentar