Design an algorithm in pseudocode that will receive two integer

Berikut ini adalah pertanyaan dari fikrinaufal411 pada mata pelajaran TI untuk jenjang Sekolah Menengah Atas

Design an algorithm in pseudocode that will receive two integer items from a terminal operator, and display to the screen their sum, difference, product, and quotient. Note that the quotient calculation (first integer divided by second integer) is only to be performed if the second integer does not equal zero.​

Jawaban dan Penjelasan

Berikut ini adalah pilihan jawaban terbaik dari pertanyaan diatas.

I’ve answered your question in this link: yomemimo.com/tugas/51947782.
So, pseudocodes presented here are based on those flowcharts.

Here are the required pseudocodes.

Notes:

  • You may substitute INPUT for READ, and OUTPUT for PRINT.
  • Comment lines are started by # character.
  • {var} means type-casting the var value into string.
  • != means "doesn't equal to". You may change it to something else which is commonly used, like <>.

_____________

Pseudocode #1
Using 4 additional variables for sum, difference, product, and quotient.

# Declaration
DECLARE a, b, sum, diff, prod, quot AS INTEGER
# User inputs two numbers.
READ a, b
# Process: calculate sum, diff, and prod.
sum ← a + b
diff ← a – b
prod ← a * b
# Output sum, diff, and prod.
PRINT ”{a} + {b} = {sum}“
PRINT ”{a} – {b} = {diff}“
PRINT ”{a} * {b} = {prod}“
# Calculate quotient
IF b != 0 THEN
   quot ← a / b
   PRINT ”{a} / {b} = {quot}“
ELSE
   PRINT ”{a} / {b} = undefined“
   # or raise a division-by-zero error exception

_____________

Pseudocode #2
Using only one additional variable for storing all operation results.

# Declaration
DECLARE a, b, result AS INTEGER
# User inputs two numbers.
READ a, b
# Process each calculation, and then print the result.
result ← a + b
PRINT ”{a} + {b} = {result}“
result ← a – b
PRINT ”{a} – {b} = {result}“
result ← a * b
PRINT ”{a} * {b} = {result}“
# Calculate quotient
IF b != 0 THEN
   result ← a / b
   PRINT ”{a} / {b} = {result}“
ELSE
   PRINT ”{a} / {b} = undefined“
   # or raise a division-by-zero error exception

Semoga dengan pertanyaan yang sudah terjawab oleh henriyulianto dapat membantu memudahkan mengerjakan soal, tugas dan PR sekolah kalian.

Apabila terdapat kesalahan dalam mengerjakan soal, silahkan koreksi jawaban dengan mengirimkan email ke yomemimo.com melalui halaman Contact

Last Update: Fri, 02 Dec 22