Question : Write a C++ Program to Print Half Pyramid using Asterisk?
Explain: C++ Question about Print Half Pyramid using *.
Example of 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 = 1; inner <= rows; inner++)
{
// inner Loop
for(outer = 1; outer <= inner;outer++)
{
// inner loop display * , can be edit other symbol
cout <<"* ";
}
// outer loop newline after complete inner loop condition
cout <<endl;
}
return 0;
}
Output:
Explain: C++ Question about Print Half Pyramid using *.
Example of 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 Half Pyramid using Asterisk [*]
*************************************************************
***************** By www.cpplanguage.com *********************/
/************************************************************
C++ Program for Print 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 = 1; inner <= rows; inner++)
{
// inner Loop
for(outer = 1; outer <= inner;outer++)
{
// inner loop display * , can be edit other symbol
cout <<"* ";
}
// outer loop newline after complete inner loop condition
cout <<endl;
}
return 0;
}
Output:
No comments:
Post a Comment