Q:

C++ Program To Print A Given Triangle of STARS

0

Write C++ Program To Print A Given Triangle of STARS Using As-trick ( * )

                                *
                             * * *
                          * * * * *
                        * * * * * * *
                     * * * * * * * * *

Logic :- 

For Printing any pattern remember always use For loop .In mostly pattern two for loops require first loop for Row and second for Column .May Be in your pattern for loop can be use parallel or Nested according to pattern you have to use

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{
 int i,j,k,n;

 cout<<"Enter How Many Row Print With Pattern\n";
 cin>>n;

 for(i=1; i<=n; i++)
 {
  for(j=n-1; j>=i; j--)
  {
   cout<<" ";
  }
  for(k=1; k<=(2*i-1); k++)
  {
   cout<<"*";
  }
  cout<<"\n";
 }
 return 0;
}

 

Output:

Enter How Many Row Print With Pattern

10

         *

        ***

       *****

      *******

     *********

    ***********

   *************

  ***************

 *****************

*******************

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now