Advertisement
JosepRivaille

P87198: Octàgons facilets

Mar 5th, 2015
1,438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: Llegeix diversos naturals >= 2
  6. //Post: Escriu un octàgon de mida n
  7. int main() {
  8.     int n;
  9.     while (cin >> n) {
  10.         int ce = n-1, cx = n; //Comparador espais ce i comparador x cx
  11.         for (int s = n-1; s != 0; --s) { //Files superiors
  12.             for (int e = ce; e != 0; --e) {
  13.                 cout << ' ';
  14.             }
  15.             for (int x = cx; x != 0; --x) {
  16.                 cout << 'X';
  17.             }
  18.             cout << endl;
  19.             cx = cx + 2;
  20.             --ce;
  21.         }
  22.         for (int s = n; s != 0; --s) { //Files centrals
  23.             for (int e = cx; e != 0; --e) {
  24.                 cout << 'X';
  25.             }
  26.             cout << endl;
  27.         }
  28.         cx = cx - 2;
  29.         ce = 1;
  30.         for (int s = n-1; s != 0; --s) { //Files inferiors
  31.             for (int e = ce; e != 0; --e) {
  32.                 cout << ' ';
  33.             }
  34.             ++ce;
  35.             for (int x = cx; x != 0; --x) {
  36.                 cout << 'X';
  37.             }
  38.             cx = cx -2;
  39.             cout << endl;
  40.         }
  41.         cout << endl;
  42.         }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement