Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Pyramid pattren program in C++

#include <iostream>
using namespace std;

int main() {
  int size = 5;
  for (int i = 0; i < size; i++) {
    // print spaces
    for (int j = 0; j < size - i - 1; j++) {
      cout << " ";
    }
    // print stars
    for (int k = 0; k < 2 * i + 1; k++) {
      cout << "*";
    }
    cout << "
";
  }
  return 0;
}

/* Output
    *
   ***
  *****
 *******
*********

*/
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #Pyramid #pattren #program
ADD COMMENT
Topic
Name
4+3 =