Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Diamond pattren program in C++

#include <iostream>
using namespace std;

int main() {
  int size = 5;
  // upside pyramid
  for (int i = 1; i <= size; i++) {
    // printing spaces
    for (int j = size; j > i; j--) {
      cout << " ";
    }
    // printing star
    for (int k = 0; k < i * 2 - 1; k++) {
      cout << "*";
    }
    cout << "
";
  }
  // downside pyramid
  for (int i = 1; i <= size - 1; i++) {
    // printing spaces
    for (int j = 0; j < i; j++) {
      cout << " ";
    }
    // printing star
    for (int k = (size - i) * 2 - 1; k > 0; k--) {
      cout << "*";
    }
    cout << "
";
  }
  return 0;
}

/* Output
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
*/
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #Diamond #pattren #program
ADD COMMENT
Topic
Name
8+7 =