Page 126 - MODUL ALGORTIMA DAN PEMROGRAMAN
P. 126

Ini contoh perulangan
                  Ini contoh perulangan
                  Ini contoh perulangan
                  Ini contoh perulangan
                  Ini contoh perulangan


                  2.  Contoh 2 – Program penggunaan while

                                                KODE PROGRAM BAHASA C
                  #include <stdio.h>

                  int main() {
                      int i = 0;

                      while (i < 5) {
                          printf("This is a loop example\n");
                          i++;
                      }

                      return 0;
                  }


                                               KODE PROGRAM BAHASA C++
                  #include <iostream>
                  using namespace std;

                  int main(int argc, char *argv){
                         int i = 0;
                         while(i<5){
                                cout<<"Ini contoh perulangan"<<endl;
                                i++;
                         }
                  }

                  Output:
                  Ini contoh perulangan
                  Ini contoh perulangan
                  Ini contoh perulangan
                  Ini contoh perulangan
                  Ini contoh perulangan

                  --------------------------------

                  3.  Contoh 3 – Program penggunaan do-while
                                                KODE PROGRAM BAHASA C
                  #include <stdio.h>

                  int main() {
                      int i = 5;
                      do {
                          printf("This is an example of a loop\n");
                          i++;
                      } while (i < 5);

                      return 0;
                  }



                                                                                                         103
   121   122   123   124   125   126   127   128   129   130   131