Page 61 - MODUL ALGORTIMA DAN PEMROGRAMAN
P. 61

KODE PROGRAM BAHASA C++
                  #include <iostream>
                  using namespace std;
                  main() {
                     int a = 21;
                     int b = 10;
                     int c ;
                     c = a + b;
                     cout << a << " + " << b << " = " << c << endl ;
                     c = a - b;
                     cout << a << " - " << b << " = " << c << endl ;
                     c = a * b;
                     cout << a << " * " << b << " = " << c << endl ;
                     c = a / b;
                     cout << a << " / " << b << " = " << c << endl ;
                     c = a % b;
                     cout << a << " % " << b << " = " << c << endl ;

                     return 0;
                  }

                  Output:
                  21 + 10 = 31
                  21 - 10 = 11
                  21 * 10 = 210
                  21 / 10 = 2
                  21 % 10 = 1
                  •   Jika nilai “a” dan “b” nya dimasukkan secara manual, berikut contoh sintaksnya.

                                               KODE PROGRAM BAHASA C++
                  #include <iostream>
                  using namespace std;
                  int main(){
                      int a, b;
                      cout << "Inputkan nilai a: ";
                      cin >> a;
                      cout << "Inputkan nilai b: ";
                      cin >> b;
                      cout << "Hasil a + b: " << a + b << endl;
                      cout << "Hasil a - b: " << a - b << endl;
                      cout << "Hasil a * b: " << a * b << endl;
                      cout << "Hasil a / b: " << a / b << endl;
                      cout << "Hasil a % b: " << a % b << endl;

                      return 0;
                  }

                  Output:

                  Inputkan nilai a: 20
                  Inputkan nilai b: 5
                  Hasil a + b: 25
                  Hasil a - b: 15
                  Hasil a * b: 100
                  Hasil a / b: 4
                  Hasil a % b: 0





                                                                                                          38
   56   57   58   59   60   61   62   63   64   65   66