SPLIT PYRAMID PATTERN IN C++ LANGUAGE
AMRUHA AHMED
10th October,2023.
This article will aid you in the creation of a split pyramid pattern in C++ language using a combination of nested loops.
DELVING DEEPER:
- 1.This pattern requires the usage of nested loops to print the asterisks in the appropriate manner
- 2.One separate variable is required to check the number of spaces printed on the screen before the asterisks are printed
BREAK-UP OF THE PATTERN:
- 1.A total of 7 rows need to be printed in the pattern.
- 2.On each side of the split, the asterisks keep increasing by 1 after each iteration.
- 3.The dashes are an indication of spaces required. Before the outer loop begins, the space variable is initialized to 7 i.e the number of rows of asterisks to be printed on the screen.As observed from the above pattern, the spaces keep decreasing by 1 after each iteration.
- 4.The set of asterisks on the left side of the split are printed on the screen depending on the value of the outer loop counter.
- 5.A space is printed on the screen to impart the split look to the pyramid.
- 6.The number of asterisks to be printed on the right side of the split are determined by the value of the outer loop counter.
PROGRAM:
#include<iostream>
using namespace std;
int main()
{
int s=7;//number of spaces to be printed
int i,j;//loop counters
for(i=1;i<=7;i++)
{
for(j=1;j<=s;j++)
{
cout<<" ";
}
for(j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<" ";
for(j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<"\n";
s--;
}
return 0;
}
OUTPUT: