Monday, 23 November 2015

C++ Program To Print A Given Triangle of STARS

Problem :- 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 if you don't know about how to print pattern then i refer first print this pattern by Own  C++ Program To Print A Given Pattern Or Series Like 12345,5432,234,43,3

Solution :-

#include<iostream>
using namespace std;
int main()
{
//By-Ghanendra Yadav
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:-

C++ Program To Print A Given Triangle of STARS

No comments:
Write comments

Recommended Posts × +