Search code examples
c++c++11visual-c++clionvisual-c++-2012

Printin a X with *


i wanna print a X with * , i have done the left side of the X but i don't know how to print the other side (flip/mirror) . if you run this codes it will print just the left side of (X) and now i wanna print the right side of (X) ? so what should i do to complete the (X) using stars(*)? thank you guys. i was wondering is it possible to do this?(i'm a newbie to programming)

#include <iostream>

// Expected output pattern:
//
//    *     *
//     *   *
//      * *
//       *
//      * *
//     *   *
//    *     *

using namespace std;

int main() {
   cout << "Printing X with star(*)" << endl;
   cout << endl;
   int i;
   int p;
   for (i = 1; i <= 10; i++) {

      for (int j = 1; j <= 10; j++) {
         if (j > i) break;
         cout << " ";
         cout << "\t";
      }
      cout << "\t\t\t\t";
      for (p = 1; p <= 10; p++) {

         cout << "*";
      }
      cout << endl;

   }
   for (i = 10; i >= 1; i--) {
      for (int j = 1; j <= 10; j++) {
         if (j > i) break;
         cout << " ";
         cout << "\t";
      }
      cout << "\t\t\t\t";
      for (p = 1; p <= 10; p++) {
         cout << "*";

      }
      cout << endl;
   }
   return 0;
}

Solution

  • ok thank you every one that helped me , i found the answer i wanted after almost 6 hours and here is the answer:

    #include <iostream>
    
    using namespace std;
    
    int main() {
    cout << "Printing X with stars" << endl;
    cout << endl;
    int i;
    int p;
    int k;
    int s;
    int count = 72;
    for (i = 1; i <= 10; i++) {
    
        for (int j = 1; j <= 10; j++) {
            if (j > i) break;
            cout << " ";
            cout << "\t";
        }
        cout << "\t\t\t\t";
        for (p = 1; p <= 10; p++) {
    
            cout << "* ";
        }
        for (k=1; k<=count; k++){
            cout << " ";
    
        }
    
        count-=8;
        for (s=1; s<=10; s++){
            cout << "* ";
        }
        cout << endl;
    }
    count = 0;
        for (i = 10; i >= 1; i--) {
            for (int j = 1; j <= 10; j++) {
                if (j > i) break;
                cout << " ";
                cout << "\t";
            }
            cout << "\t\t\t\t";
            for (p = 1; p <= 10; p++) {
                cout << "* ";
            }
            for (k=1; k<=count; k++) {
                cout << " ";
            }
            count +=8;
    
            for (s=1; s<=10; s++){
                cout << "* ";
            }
            cout << endl;
            if (count == 80) break;
    }
    return 0;
    }