Halo, posting kali ini kita akan membahas program kombinasi, yaitu Input Array, Tampil Array, mencari Nilai minimun & maksimum. Program ini menggunakan switch-case. Langsung saja lihat script C++ nya dibawah ini :
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int pilihan,i,indeks;
float ratarata,jumlah;
int minimum;
int maksimum;
int bilangan1;
int bilangan[100];
char pil;
menu:
system("cls");
cout << "========================" << endl;
cout << " MENU " << endl;
cout << "========================" << endl;
cout << "1. Input Array " << endl;
cout << "2. Tampilkan Array " << endl;
cout << "3. Cari Nilai Minimum " << endl;
cout << "4. Cari Nilai Maksimum " << endl;
cout << "5. Exit " << endl;
cout << "========================" << endl;
cout << "Masukkan Pilihan : "; cin >> pilihan;
cout << "========================" << endl;
switch(pilihan){
case 1:
cout << "Masukkan Jumlah Array : "; cin >> bilangan1;
for(i=0;i<bilangan1;i++){
cout << "Masukkan Bilangan ke-"<<i+1<< " :";
cin >> bilangan[i];
}
break;
case 2:
for (i=0;i<bilangan1;i++){
cout << "Bilangan Array ke-"<<i+1<< " :"<<bilangan[i]<<endl;
}
break;
case 3:
minimum=bilangan[0];
for (indeks=0;indeks<bilangan1;indeks++)
if (minimum>bilangan[indeks])
{
minimum=bilangan[indeks];
}
cout << "Bilangan Minimumnya adalah "<<minimum<<endl;
break;
case 4:
maksimum=bilangan[0];
for (indeks=0;indeks<bilangan1;indeks++)
if (maksimum<bilangan[indeks])
{
maksimum=bilangan[indeks];
}
cout << "Bilangan Maksimumnya adalah "<<maksimum<<endl;
break;
case 5:
return 0;
}
system ("pause");
goto menu;
return 0;
}
#include <stdlib.h>
using namespace std;
int main()
{
int pilihan,i,indeks;
float ratarata,jumlah;
int minimum;
int maksimum;
int bilangan1;
int bilangan[100];
char pil;
menu:
system("cls");
cout << "========================" << endl;
cout << " MENU " << endl;
cout << "========================" << endl;
cout << "1. Input Array " << endl;
cout << "2. Tampilkan Array " << endl;
cout << "3. Cari Nilai Minimum " << endl;
cout << "4. Cari Nilai Maksimum " << endl;
cout << "5. Exit " << endl;
cout << "========================" << endl;
cout << "Masukkan Pilihan : "; cin >> pilihan;
cout << "========================" << endl;
switch(pilihan){
case 1:
cout << "Masukkan Jumlah Array : "; cin >> bilangan1;
for(i=0;i<bilangan1;i++){
cout << "Masukkan Bilangan ke-"<<i+1<< " :";
cin >> bilangan[i];
}
break;
case 2:
for (i=0;i<bilangan1;i++){
cout << "Bilangan Array ke-"<<i+1<< " :"<<bilangan[i]<<endl;
}
break;
case 3:
minimum=bilangan[0];
for (indeks=0;indeks<bilangan1;indeks++)
if (minimum>bilangan[indeks])
{
minimum=bilangan[indeks];
}
cout << "Bilangan Minimumnya adalah "<<minimum<<endl;
break;
case 4:
maksimum=bilangan[0];
for (indeks=0;indeks<bilangan1;indeks++)
if (maksimum<bilangan[indeks])
{
maksimum=bilangan[indeks];
}
cout << "Bilangan Maksimumnya adalah "<<maksimum<<endl;
break;
case 5:
return 0;
}
system ("pause");
goto menu;
return 0;
}
Sekian & semoga bermanfaat!
Thanks for reading & sharing RZDev: Belajar Programming!
nice information min
ReplyDeleteobeng set