Advertisement
_fur

_fur | C++ Aditya Bayu

Nov 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(void)
  6. {
  7.         // Deklarasi variable
  8.         unsigned int line, n, i, j, totalLine, temp;
  9.         unsigned int pos = 0;
  10.  
  11.         // Jumlah input
  12.         cin >> n;
  13.         if (n > 26) return 22;
  14.  
  15.         // Menentukan jumlah baris
  16.         for (totalLine = 1, temp = 1; temp < n; temp += ++totalLine);
  17.  
  18.         for (line = 1; line <= totalLine; line++) {
  19.                 // Tulis spasi
  20.                 for (i = 0; i < (totalLine - line); i++)
  21.                         cout << " ";
  22.  
  23.                 // Tulis karakter
  24.                 for (j = 0; j < line && pos < n; j++)
  25.                         cout << static_cast<char>('A' + pos++) << " ";
  26.  
  27.                 // Akhiri baris
  28.                 cout << endl;
  29.         }
  30.  
  31.         return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement