Signup/Sign In

C++ Program To Print Half Pyramid Alternative Using ( * ) Star And Alphabet

In this tutorial, we will be learning about printing the half pyramid using the alternative * and an alphabet, let us say it will be "A" for instance.

*
*A
*A*
*A*A
*A*A*
*A*A*A

The basic approach behind making this pattern will have the count that if the count value is odd it will print "*" and otherwise "A".There will be two loops one inside another to make the half pyramid and then to implement the required pattern we will apply the conditions within the inside loop.

C++ Program To Print Half Pyramid Alternative

#include<iostream>
using namespace std;

int main()
{
int i,j,n;
cout<<"Enter the  Of Row\n";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(j%2==0)
cout<<"A";
else
cout<<"*";
}
cout<<"\n";
}
return 0;
}


Enter the No Of Row
6
*
*A
*A*
*A*A
*A*A*
*A*A*A

Conclusion

This tutorial is mainly based on how we can make any shape using two different character values having different values in the positions for corresponding rows.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.