Search
 
SCRIPT & CODE EXAMPLE
 

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
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
*/
Comment

PREVIOUS NEXT
Code Example
Cpp :: C++ Rectangular Form 
Cpp :: sfml get position 
Cpp :: c++ cyclic barrier 
Cpp :: how to calculate marks in C++ 
Cpp :: avl tree c++ 
Cpp :: c++ cout format specifier for correct number of decimal points 
Cpp :: find number of 1s in a binary cv::mat image 
Cpp :: Browse Folder Dialog, Search Folder and All Sub Folders using C/C++ 
Cpp :: cosnt cast 
Cpp :: Make them equal codechef solution in c++ 
Cpp :: esp8266 wifi.localip() to string 
Cpp :: c++ sigabrt 
Cpp :: c++ asio read full socket data into buffer 
Cpp :: cf 633b trivial problem explanation 
Cpp :: appdivind c++ stuctures 
Cpp :: 7 9 C:UsersAliyahDocumentsshut up.cpp [Error] expected unqualified-id before string constant 
Cpp :: C++ How to insert and print array elements? 
Cpp :: minimum no of jump required to reach end of arry 
Cpp :: C++ Ranged Based for Loop 
Cpp :: 1281. Subtract the Product and Sum of Digits of an Integer leetcode solution in c++ 
Cpp :: Required Length 
Cpp :: is vowel c++/c 
Cpp :: online convert c++ code to assembly language 
Cpp :: executing linux scripts 
Cpp :: double pointers C++ 
Cpp :: fenwick tree 
Cpp :: c++ for 
Cpp :: insert into a vector more than once c++ 
Cpp :: how to make a c++ iostream program restart when finished 
C :: rename c 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =