Skip to content

Wignaw

Home » C++ Programs To Create Pyramid and Pattern Number

how to write code C++ Programs 1 Pyramid

  • by
how to write code C++ Programs 1

Programs to Print Triangles Using *, Numbers, and Characters

Example 1: Program to Print a Half-Pyramid Using *

Program to Print a Half-Pyramid Using *

example Code

#include <iostream>
using namespace std;

int main() {

    int rows;

    cout << "Enter number of rows: ";
    cin >> rows;

    for(int i = 1; i <= rows; ++i) { 
        for(int j = 1; j <= i; ++j) { 
            cout << "* "; 
        }
        cout << "\n"; // Move to the next line after printing stars for each row
    }

    return 0;
}


wignaw

C++ Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *