Question : Write a C++ Program to Print Inverted Half Pyramid using Asterisk?
Explain: C++ Question about Print Inverted Half Pyramid using *.
Example of Inverted Half Pyramid with *
* * * * *
* * * *
* * *
* *
*
It is best example of Nested for Loop using outer and inner loop for print star. you can edit star with other symbol like - , ^ , $.
#include <iostream>
using namespace std;
int main()
{
// set rows for print , can be customized
int rows=7;
int inner,outer;
// outer Loop
for(inner = rows; inner >=1; inner--)
{
// inner Loop based on outer condition
for(outer = 1; outer <= inner;outer++)
{
// inner loop display star , can be change to other char
cout <<"* ";
}
// outer loop newline after complete inner loop condition
cout <<endl;
}
return 0;
}
Output:
Explain: C++ Question about Print Inverted Half Pyramid using *.
Example of Inverted Half Pyramid with *
* * * * *
* * * *
* * *
* *
*
It is best example of Nested for Loop using outer and inner loop for print star. you can edit star with other symbol like - , ^ , $.
Solution:
/************************************************************
C++ Program for Print Inverted Half Pyramid using Asterisk [*]
*************************************************************
***************** By www.cpplanguage.com *********************/
/************************************************************
C++ Program for Print Inverted Half Pyramid using Asterisk [*]
*************************************************************
***************** By www.cpplanguage.com *********************/
#include <iostream>
using namespace std;
int main()
{
// set rows for print , can be customized
int rows=7;
int inner,outer;
// outer Loop
for(inner = rows; inner >=1; inner--)
{
// inner Loop based on outer condition
for(outer = 1; outer <= inner;outer++)
{
// inner loop display star , can be change to other char
cout <<"* ";
}
// outer loop newline after complete inner loop condition
cout <<endl;
}
return 0;
}
Output:
No comments:
Post a Comment