fork download
  1. // Nicolas Ruano CS1A Chapter 2, Pp. 83, #16
  2.  
  3. /*************************************************************************
  4. *
  5. *------------------------------------------------------------------------*
  6. * Output is when the program releses the result of a set of stars forming*
  7. * a shape of a diamond . *
  8. * -----------------------------------------------------------------------*
  9. * Input *
  10. * The number of stars being provided and how much to craft a triangle *
  11. * *
  12. * Output *
  13. * The number of stars shoewcased a diamond shape built on stars *
  14. *************************************************************************/
  15.  
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main() {
  20. int rows = 4; //Half of the diamond height (middle line at row 4)
  21.  
  22. // Top half (including middle row)
  23. for (int i = 1; i <= rows; i++) {
  24. // Print spaces
  25. for (int j = i; j < rows; j++) {
  26. cout << " ";
  27. }
  28. // Print stars
  29. for (int k = 1; k <= (2 * i - 1); k++) {
  30. cout << "*";
  31. }
  32. cout << endl;
  33. }
  34.  
  35. // Bottom half
  36. for (int i = rows - 1; i >= 1; i--) {
  37. // Print spaces
  38. for (int j = rows; j > i; j--) {
  39. cout << " ";
  40. }
  41. // Print stars
  42. for (int k = 1; k <= (2 * i - 1); k++) {
  43. cout << "*";
  44. }
  45. cout << endl;
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
   *
  ***
 *****
*******
 *****
  ***
   *