Advertisement
akmalgtg

Persegi Berpola

May 9th, 2020
1,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int p;
  8.     string x, y, a, b;
  9.  
  10.     cout << "Masukkan panjang atau lebar dari persegi: ";
  11.     cin >> p;
  12.     cout << "Karakter 1: ";
  13.     cin >> a;
  14.     cout << "Karakter 2: ";
  15.     cin >> b;
  16.     cout << endl;
  17.  
  18.     for (int i = 0; i < p; ++i)
  19.     {
  20.         if (i % 2 == 0)
  21.         {
  22.             x = a;
  23.             y = b;
  24.         } else {
  25.             x = b;
  26.             y = a;
  27.         }
  28.  
  29.         for (int o = 0; o < p; ++o)
  30.         {
  31.             if (o % 2 == 0)
  32.             {
  33.                 cout << " " << x;
  34.             } else {
  35.                 cout << " " << y;
  36.             }
  37.         }
  38.  
  39.         cout << endl;
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement