[Solved] C++ Create Triangles with For Loops [closed]


You need to output spaces between the triangles:

#include <iostream>
using namespace std;

int main() {
  const int size = 6;
  int uzunluk = size;

  for (int i = 0; i < size; i++) {

    for (int j = 0; j < uzunluk; j++) {
      cout << "*";
    }
    for (int j = 0; j < (size - uzunluk + 1) * 2; j++){
      cout << " ";
    }
    for (int j = 0; j < uzunluk; j++) {
      cout << "*";
    }
    cout << endl;
    uzunluk--;
  }

  cout << endl;

  for (int i = 0; i < size; i++) {

    for (int j = 0; j <= uzunluk; j++) {
      cout << "*";
    }
    for (int j = 0; j < (size - uzunluk) * 2; j++){
      cout << " ";
    }
    for (int j = 0; j <= uzunluk; j++) {
      cout << "*";
    }
    cout << endl;
    uzunluk++;
  }
}

4

solved C++ Create Triangles with For Loops [closed]