Page 77 - MODUL ALGORTIMA DAN PEMROGRAMAN
P. 77

presidenku = Megawati;

                      // Output the President's number using the enum values
                      printf("Presiden Indonesia ke-%d\n", presiden + 1);
                      printf("Presiden Indonesia ke-%d\n", presidenku + 1);

                      return 0;
                  }

                                               KODE PROGRAM BAHASA C++
                  #include <iostream>
                  using namespace std;
                  enum namaPresiden{
                         Soekarno,
                         Soeharto,
                         Habibie,
                         Megawati,
                         Gusdur,
                         SBY,
                         Jokowi
                  }presidenku;

                  int main() {
                         namaPresiden presiden;
                         presiden = Habibie;
                         cout<<"Presiden Indonesia ke-"<<presiden + 1<<endl;
                         presidenku = Megawati;
                         cout<<"Presiden Indonesia ke-"<<presidenku + 1;
                         return 0;
                  }


                  Output:
                  Presiden Indonesia ke-3
                  Presiden Indonesia ke-4

                  4.  Contoh 4 – Program penggunaan typedef

                                                KODE PROGRAM BAHASA C
                  #include <stdio.h>

                  typedef int bbulat;
                  typedef float breal;

                  int main() {
                      bbulat usia = 22;
                      breal beratBadan = 46.0;

                      printf("Saya Ainun\n");
                      printf("Usia saya adalah %d tahun\n", usia);
                      printf("Berat badan saya adalah %f Kg\n", beratBadan);

                      return 0;
                  }








                                                                                                          68
   72   73   74   75   76   77   78   79   80   81   82