Contoh Soal atau Kasus
Searching Array Conditional (tidak pakai loop)
//judul : cari array
//AUTHOR : RIFKY BINTANG P
#include <iostream>
using namespace std;
//kamus
int bil1,angka,bilangan,values,nilai;
int data[5];
int cari,goleki, y,x;
//deskripsi
int main()
{
cout << "Input Nilai : \n" << endl;
cout << "Masukkan Bilangan KE 1: "; cin >> bil1;
cout << "Masukkan Bilangan KE 2: "; cin >> angka;
cout << "Masukkan Bilangan KE 3: "; cin >> bilangan;
cout << "Masukkan Bilangan KE 4: "; cin >> values;
cout << "Masukkan Bilangan KE 5: "; cin >> nilai;
cout << "masukkan apa yang kamu cari : " << endl; cin >> cari;
if (cari==bil1)
{
cout << "Ketemu" << endl;
}else if(cari==angka)
{
cout << "ketemu" << endl;
}else if(cari==bilangan)
{
cout << "Ketemu" << endl;
}else if(cari==values)
{
cout << "Ketemu" << endl;
}else if(cari==nilai)
{
cout << "Ketemu" << endl;
}else
{
cout << "rak ketemu" << endl;
}
cout << "Input data: " << endl;
cout << "Masukkan Bilangan Ke Data Index ke 1 = "; cin >> data[0];
cout << "Masukkan Bilangan Ke Data Index ke 4 = "; cin >> data[4];
cout << "Masukkan Bilangan Ke Data Index ke 3 = "; cin >> data[3];
cout << "Masukkan Bilangan Ke Data Index ke 2 = "; cin >> data[1];
cout << "Masukkan Bilangan Ke Data Index ke 5 = "; cin >> data[2];
cout << "Bilangan anda adalah...\n" << endl;
cout << bil1 << endl;
cout << angka << endl;
cout << bilangan << endl;
cout << values << endl;
cout << nilai << endl;
cout << "Data anda adalah.....\n" << endl;
cout << data[4] << endl;
cout << data[1] << endl;
cout << data[5] << endl;
cout << data[3] << endl;
cout << data[2] << endl;
while(y <6)
{
if(goleki==data[y])
{
cout << "ditemukan di index ke" << y;
}else
{
cout << "tidak ketemu";
}
y = y + 1;
}
x = 0;
do
{
cout << "isi data index ke" << x << "-" << data[x] << endl;
x = x + 1;
}while(x < 6);
}
Komentar
Posting Komentar