Dalam Studi Ilmu Komputer dan Tehnik Operasi Aritmatika
(Arithmetic Operators) sangat selalu digunakan terutama dalam penerapan Logika pemrograman.
Operasi Aritmatika
Simbol |
Operator |
+ |
Penjumlahan |
- |
Pengurangan |
* |
Perkalian |
/ |
Pembagian |
% |
Modulo |
Sebelum kita melanjutkan Operasi aritmatika lanjutan, kita akan mengenal denagan Tabel Kebenaran (Truth table ).
Tabel Kebenaran
Logical Identity
p |
p |
Operand |
Value |
T |
T |
F |
F |
Logical Negation
p |
¬p |
T |
F |
F |
T |
Truth table for all binary logical operators
P |
Q |
|
F0 |
NOR1 |
Xq2 |
¬p3 |
↛4 |
¬q5 |
XOR6 |
NAND7 |
|
AND8 |
XNOR9 |
q10 |
if/then11 |
p12 |
then/if13 |
OR14 |
T15 |
T |
T |
|
F |
F |
F |
F |
F |
F |
F |
F |
|
T |
T |
T |
T |
T |
T |
T |
T |
T |
F |
|
F |
F |
F |
F |
T |
T |
T |
T |
|
F |
F |
F |
F |
T |
T |
T |
T |
F |
T |
|
F |
F |
T |
T |
F |
F |
T |
T |
|
F |
F |
T |
T |
F |
F |
T |
T |
F |
F |
|
F |
T |
F |
T |
F |
T |
F |
T |
|
F |
T |
F |
T |
F |
T |
F |
T |
Com |
|
✓ |
✓ |
|
|
|
|
✓ |
✓ |
|
✓ |
✓ |
|
|
|
|
✓ |
✓ |
L id |
|
|
|
F |
|
|
|
F |
|
|
T |
T |
TF |
T |
|
|
F |
|
R id |
|
|
|
|
|
F |
|
F |
|
|
T |
T |
|
|
TF |
T |
F |
|
Logical Conjunction
p |
q |
p ∧ q |
T |
T |
T |
T |
F |
F |
F |
T |
F |
F |
F |
F |
Logical Disjunction
p |
q |
p ∨ q |
T |
T |
T |
T |
F |
T |
F |
T |
T |
F |
F |
F |
Logical Implication
p |
q |
p → q |
T |
T |
T |
T |
F |
F |
F |
T |
T |
F |
F |
T |
Logical Equality
p |
q |
p ≡ q |
T |
T |
T |
T |
F |
F |
F |
T |
F |
F |
F |
T |
Exclusive Disjunction
p |
q |
p ⊕ q |
T |
T |
F |
T |
F |
T |
F |
T |
T |
F |
F |
F |
Logical NAND
p |
q |
p ↑ q |
T |
T |
F |
T |
F |
T |
F |
T |
T |
F |
F |
T |
p |
q |
p ∧ q |
¬(p ∧ q) |
¬p |
¬q |
(¬p) ∨ (¬q) |
T |
T |
T |
F |
F |
F |
F |
T |
F |
F |
T |
F |
T |
T |
F |
T |
F |
T |
T |
F |
T |
F |
F |
F |
T |
T |
T |
T |
Logical NOR
p |
q |
p ↓ q |
T |
T |
F |
T |
F |
F |
F |
T |
F |
F |
F |
T |
p |
q |
p ∨ q |
¬(p ∨ q) |
¬p |
¬q |
(¬p) ∧ (¬q) |
T |
T |
T |
F |
F |
F |
F |
T |
F |
T |
F |
F |
T |
F |
F |
T |
T |
F |
T |
F |
F |
F |
F |
F |
T |
T |
T |
T |
Keterangan
- T = true, F = false
- = AND (logical conjunction)
- = OR (logical disjunction)
- = XOR (exclusive or)
- = XNOR (exclusive nor)
- = conditional "if-then"
- = conditional "(then)-if"
________________________________________________________________________
Penerapan dalam Pemrograman Expresi Operator
program Project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ Penerapan Operator dengan Program Pascal };
begin
WriteLn('1. 5 + 6 / 3 =',5+6/3:0:2);
WriteLn('2. 7 X 2 + 8 * 3 =',7*2+8*3);
WriteLn('3. 10 - 5 ^ 2 * 5 + 15 =',10-(5*5)*5+15);
WriteLn('4. 15 / 5 + 10 *3 =',15/5+10*3:0:2);
WriteLn('5. (53 MOD 9) + (53 DIV 9) + 3 * 4 - 5 =',(53 MOD 9)+(53 DIV 9)+3*4-5);
WriteLn('6. 12 + 5 X (10 MOD 3) - 2^3 + (23 DIV 3)=',12+5*(10 MOD 3)-(2*2)*3+(23 DIV 3));
WriteLn('7. 9 - 5 X 2 =',9-5*2);
WriteLn('8. 5 / 2 X 3 =',5/2*3:0:2);
WriteLn('9. 5 DIV 2 X 3 =',5 DIV 2*3);
WriteLn('10. 2 X (5 + 2) =',2*(5+2));
WriteLn('11. 7 + 3 MOD 2 =',7+3 MOD 2);
WriteLn('12. (7 + 3) MOD 2 = ',(7+3) MOD 2);
WriteLn('13. 2 DIV 3 + 3 / 5 =',2 DIV 3+3/5:0:2);
WriteLn('14. -20 / 5 X 2=',-20/5*2:0:2);
WriteLn('15. 60 + 2 x 5 - 7 =',60+2*5-7);
WriteLn('16. 60 + 2 X (5 - 7)=',60+2*(5-7));
WriteLn('17. 1 + 1 X 3 =', 1+1*3);
WriteLn('18. (1 + 2 ) X 3 =',(1+2)*3);
WriteLn('19. 5 X (5 + (6 - 2 )+1) =',5*(5+(6-2)+1));
WriteLn;
readln;
end.
Hasilnya sebagai berikut
Anda suka artikel di atas ???
Klik salah satu atau ketiga tombol di bawah ini :
Jangan Lupa Baca Juga :
0 komentar:
Posting Komentar