fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void iterative_function (char a, char b, int width) {
  5. int i = width;
  6. while (i > 0) {
  7. cout << string(i, a) << string(width-i, b) << endl;
  8. i -= 2;
  9. }
  10. i = width % 2;
  11. while (i <= width) {
  12. cout <<string(i, a) << string(width-i, b) << endl;
  13. i += 2;
  14. }
  15. }
  16.  
  17. int main() {
  18. iterative_function('X', '-', 5);
  19. return 0;
  20. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
XXXXX
XXX--
X----
X----
XXX--
XXXXX