Page 63 - MODUL ALGORTIMA DAN PEMROGRAMAN
P. 63

hasil = a == b;
                      printf("a == b = %d\n", hasil);
                      hasil = a != b;
                      printf("a != b = %d\n", hasil);

                      return 0;
                  }

                                               KODE PROGRAM BAHASA C++
                  #include <iostream>

                  using namespace std;

                  int main(){
                      int a = 4, b = 3;
                      bool hasil;
                      cout << "a = " << a << endl;
                      cout << "b = " << b << endl;

                      // menggunakan operator pembanding
                      hasil = a > b;
                      cout << "a > b = " << hasil << endl;
                      hasil = a < b;
                      cout << "a < b = " << hasil << endl;
                      hasil = a >= b;
                      cout << "a >= b = " << hasil << endl;
                      hasil = a <= b;
                      cout << "a <= b = " << hasil << endl;
                      hasil = a == b;
                      cout << "a == b = " << hasil << endl;
                      hasil = a != b;
                      cout << "a != b = " << hasil << endl;

                      return 0;
                  }
                  Output:

                  a = 4
                  b = 3
                  a > b = 1
                  a < b = 0
                  a >= b = 1
                  a <= b = 0
                  a == b = 0
                  a != b = 1

                  6.  Contoh 6 – Program penggunaan operator logika
                                                KODE PROGRAM BAHASA C
                  #include <stdio.h>

                  int main() {
                      int a = 1; // True (non-zero integer in C)
                      int b = 0; // False (zero integer in C)
                      int hasil;

                      printf("a = %d\n", a);
                      printf("b = %d\n", b);

                      // Logical AND
                      hasil = a && b;
                      printf("a && b = %d\n", hasil);
                                                                                                          40
                        // Logical OR
                      hasil = a || b;
                      printf("a || b = %d\n", hasil);
   58   59   60   61   62   63   64   65   66   67   68