Anda di halaman 1dari 6

Nama : Tsaniya Putri Anjani

NPM : 2107051019
D3 Manajemen Informatika

1. Algoritma Mencetak_Huruf_Mutu
{Algoritma untuk mencetak huruf mutu mahasiswa dengan input adalah nilai akhir}

Deklarasi
L : Array [1…50] (integer)
Nama_mahasiswa : array [‘a’…’j’] (string)
Nilai_ujian : array [0…74] (real)

Deskripsi
read (n) {baca inputan n}
if n>= 76 then
write
(“A”) else
if n>=71 and n<76
then write (“B+”)
else
if n>=66 and n<71
then write (“B”)
else
if n>=61 and n<66
then write (“C+”)
else
if n>=56 and n<61
then write (“C”)
else
if n>=50 and n<56
then write (“D”)
else
write
(“E”)
endif
endif
endif
endif
endif
endif
endif
Switch Case

 Algoritma Mencetak_Huruf_Mutu
{Algoritma untuk mencetak huruf mutu mahasiswa dengan input adalah nilai akhir}

Deklarasi
n : real {n adalah nilai yang akan diinputkan}

Deskripsi
read (n) {baca inputan
n} case (n)
n >= 76 : write (‘A’)
n>=71 and n<76 : write
(‘B+’) n>=66 and n<71 :
write (‘B’) n>=61 and n<66 :
write (‘C+’) n>=56 and
n<61 : write (‘C’) n>=50 and
n<56 : write (‘D’)
otherwise : write (‘E’)
endcase

2. Implementasi C++ dari algoritma nomor 1


#include <iostream>
using namespace std;

int main(){
float n;

cin >> n;
if (n>=76){
cout <<"A"<<endl;
} else if (n>=71 &&
n<76 ){ cout
<<"B+"<<endl;
} else if (n>=66 && n<71
){ cout
<<"B"<<endl;
} else if (n>=61 &&
n<66 ){ cout
<<"C+"<<endl;
} else if (n>=56 &&
n<61){ cout
<<"C"<<endl;
} else if (n>=50 && n<56
){ cout
<<"D"<<endl;
} else {
cout <<"E"<<endl;
}

return 0;
}
 Switch Case
#include
<iostream>
using namespace std;

int main(){
int n;
cin >>
n;
switch (n) {
case 76 ... 100
:
cout << "A" <<
endl; break;
case 71 ... 75 :
cout << "B+" <<
endl; break;
case 66 ... 70 :
cout << "B" <<
endl; break;
case 61 ... 65 :
cout << "C+" <<
endl; break;
case 56 ... 60 :
cout << "C" <<
endl; break;
case 50 ... 55 :
cout << "D" <<
endl; break;
default:
cout << "E" << endl;
}

return 0;
}
(for to do)
#include <iostream>
using namespace std;

int main(){
int bil[5], x=1, y=1;

for (x=1; x<=5; x++){


cin >> bil[x];
}

for (y=1; y<=5;y++){


cout << bil[y]<<" ";
}

return 0;
}

(Repeat until)
#include <iostream>
using namespace std;

int main(){
int bil[5], x=1;

do {
cin >>
bil[x]; x++;
} while (x<=5);

int
y=1; do
{
cin >>
bil[y]; y++;
} while (y<=5);
return 0;
}

Anda mungkin juga menyukai