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
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
Categorized in:
Tagged in:
Accenture interview questions and answers, Applied Materials interview questions and answers, area of a triangular pyramid, Atos interview questions and answers, BMC Software interview questions and answers, Bosch India Software interview questions and answers, c program to print patterns of numbers, c program to print patterns of numbers and alphabets, c program to print patterns of numbers and stars in a pyramid shape, c program to print pyramid of numbers in reverse order, c program to print pyramid pattern of numbers, c++ pattern programs, c++ program to print diamond of stars, c++ program to print pyramid of numbers, c++ program to print pyramid using *, CASTING NETWORKS INDIA PVT LIMITED interview questions and answers, Chetu interview questions and answers, Ciena Corporation interview questions and answers, cstar programme, Dell International Services India Pvt Ltd interview questions and answers, Diamond pattern programs in c, difficult number pattern programs in c, double pyramid pattern in c, eInfochips interview questions and answers, Electronics Arts Inc interview questions and answers, Flipkart interview questions and answers, Harman International interview questions and answers, Indecomm Global Services interview questions and answers, Larsen & Toubro interview questions and answers, letter pyramid c++, Mathworks India Private Limited interview questions and answers, Mavenir interview questions and answers, Mphasis interview questions and answers, nested loop c++ shapes, NetApp interview questions and answers, Oracle Corporation interview questions and answers, pascal triangle in c++ using array, pascal's triangle formula, pascal's triangle patterns, pattern code, pattern programs in c, pattern programs in java, patterns in c, PeopleStrong interview questions and answers, Philips Software Centre Pvt Ltd interview questions and answers, print and pattern, print pascal triangle c++, print pattern, programming patterns, pyramid of numbers, pyramid program in c, pyramid program in c with explanation, pyramid shape, right triangle c++, square based pyramid, SRM Technologies interview questions and answers, star pattern, star pattern in c, Symphony Teleca interview questions and answers, Tech Mahindra interview questions and answers, Tecnotree interview questions and answers, toughest pattern programs in c, triangular pyramid, volume of a square based pyramid, Wipro Infotech interview questions and answers, Wipro interview questions and answers, Yash Technologies interview questions and answers