akmalgtg icon

Persegi Berpola

akmalgtg | PRO | 05/09/20 11:14:33 PM UTC | 0 ⭐ | 1799 👁️ | Never ⏰ | []
C++ |

530 B

|

None

|

0 👍

/

0 👎

#include <iostream>
 
using namespace std;
 
int main()
{
    int p;
    string x, y, a, b;
 
    cout << "Masukkan panjang atau lebar dari persegi: ";
    cin >> p;
    cout << "Karakter 1: ";
    cin >> a;
    cout << "Karakter 2: ";
    cin >> b;
    cout << endl;
 
    for (int i = 0; i < p; ++i)
    {
        if (i % 2 == 0)
        {
            x = a;
            y = b;
        } else {
            x = b;
            y = a;
        }
 
        for (int o = 0; o < p; ++o)
        {
            if (o % 2 == 0)
            {
                cout << " " << x;
            } else {
                cout << " " << y;
            }
        }
 
        cout << endl;
    }
 
    return 0;
}

Comments