Print pyramid triangle in C++
- To print pyramid triangle in C++, we have use two for loop, the outer for loop and the inner for loop.
- The outer for loop is responsible for rows and the inner for loop is responsible for column.
- C++ programs to print different types of patterns using stars(*), numbers, and characters or alphabets.
- This C++ program prints the full pyramid using stars(*).
Sample Code in C++
#include <iostream>
using namespace std;
int main()
{
int j, rows;
cout <<"Enter number of rows: ";
cin >> rows;
for(int i = 1, k = 0; i <= rows; ++i, k = 0)
{
for(j = 1; j <= rows-i; ++j)
{
cout <<" ";
}
while(k != 2*i-1)
{
cout << "* ";
++k;
}
cout << endl;
}
return 0;
} Output
Enter number of rows : 7
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * * Tags:
Accenture interview questions and answersApplied Materials interview questions and answersarea of a triangular pyramidAtos interview questions and answersBMC Software interview questions and answersBosch India Software interview questions and answersc program to print patterns of numbersc program to print patterns of numbers and alphabetsc program to print patterns of numbers and stars in a pyramid shapec program to print pyramid of numbers in reverse orderc program to print pyramid pattern of numbersc++ pattern programsc++ program to print diamond of starsc++ program to print pyramid of numbersc++ program to print pyramid using *CASTING NETWORKS INDIA PVT LIMITED interview questions and answersChetu interview questions and answersCiena Corporation interview questions and answerscstar programmeDell International Services India Pvt Ltd interview questions and answersDiamond pattern programs in cdifficult number pattern programs in cdouble pyramid pattern in ceInfochips interview questions and answersElectronics Arts Inc interview questions and answersFlipkart interview questions and answersHarman International interview questions and answersIndecomm Global Services interview questions and answersLarsen & Toubro interview questions and answersletter pyramid c++Mathworks India Private Limited interview questions and answersMavenir interview questions and answersMphasis interview questions and answersnested loop c++ shapesNetApp interview questions and answersOracle Corporation interview questions and answerspascal triangle in c++ using arraypascal's triangle formulapascal's triangle patternspattern codepattern programs in cpattern programs in javapatterns in cPeopleStrong interview questions and answersPhilips Software Centre Pvt Ltd interview questions and answersprint and patternprint pascal triangle c++print patternprogramming patternspyramid of numberspyramid program in cpyramid program in c with explanationpyramid shaperight triangle c++square based pyramidSRM Technologies interview questions and answersstar patternstar pattern in cSymphony Teleca interview questions and answersTech Mahindra interview questions and answersTecnotree interview questions and answerstoughest pattern programs in ctriangular pyramidvolume of a square based pyramidWipro Infotech interview questions and answersWipro interview questions and answersYash Technologies interview questions and answersOther Articles
Previous