fork download
  1. //This program is for how to display diamonds on stars
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. int rows = 4; //Half of the diamond height (middle line at row 4)
  7.  
  8. // Top half (including middle row)
  9. for (int i = 1; i <= rows; i++) {
  10. // Print spaces
  11. for (int j = i; j < rows; j++) {
  12. cout << " ";
  13. }
  14. // Print stars
  15. for (int k = 1; k <= (2 * i - 1); k++) {
  16. cout << "*";
  17. }
  18. cout << endl;
  19. }
  20.  
  21. // Bottom half
  22. for (int i = rows - 1; i >= 1; i--) {
  23. // Print spaces
  24. for (int j = rows; j > i; j--) {
  25. cout << " ";
  26. }
  27. // Print stars
  28. for (int k = 1; k <= (2 * i - 1); k++) {
  29. cout << "*";
  30. }
  31. cout << endl;
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
   *
  ***
 *****
*******
 *****
  ***
   *