23/11/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

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: