Untitled

 avatar
unknown
plain_text
10 months ago
758 B
11
Indexable
#include <iostream>
#include <iomanip>  // setw untuk perapian kolom
using namespace std;

int main() {
    const int N = 10;        // batas tabel (1..10)
    const int W = 4;         // lebar kolom

    // Header kolom
    cout << setw(W) << "x";
    for (int j = 1; j <= N; j++) {
        cout << setw(W) << j;
    }
    cout << '\n';

    // Garis pemisah
    cout << setfill('-') << setw(W * (N + 1)) << "-" << '\n';
    cout << setfill(' ');

    // Isi tabel (nested loop)
    for (int i = 1; i <= N; i++) {        // outer loop: baris
        cout << setw(W) << i;             // label baris
        for (int j = 1; j <= N; j++) {    // inner loop: kolom
            cout << setw(W) << (i * j);
        }
        cout << '\n';
    }

    return 0;
}
Editor is loading...
Leave a Comment