Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

draw a pattern in c++or c

+4 votes
asked Dec 11, 2020 by VINIT SAMMIR (240 points)
edited Dec 14, 2020 by VINIT SAMMIR

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

1 Answer

–1 vote
answered Dec 13, 2020 by xDELLx (10,500 points)
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <string>
//#include <array>

constexpr int offset=20;

template <char c='*',int N=5>
struct print{
     constexpr print (){
         //std::cout<<count<<std::endl;
         for(int i=offset;i>N;--i) std::cout<<' ';
         for(int i=0;i<N;++i) std::cout<<c<<c;
         std::cout<<std::endl;
     }
      ~print(){
         for(int i=offset;i>N;--i) std::cout<<' ';
         for(int i=0;i<N;++i) std::cout<<c<<c;
         std::cout<<std::endl;        
     }
};
//Check if for loop can eliminated using TempMetaProg
/*template <>
struct print<0>
{
    static constexpr int s = 1;
};*/

int main()
{
    print<'*',1> p1;
    print<'*',3> p2;
    print<'*',5> p;
    print<'*',7> q;
    //std::cout <<p.a<<std::endl;
    //std::cout <<q.a<<std::endl;

    return 0;
}
/*

                   **                                                                                                          

                 ******                                                                                                        

               **********                                                                                                      

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

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

               **********                                                                                                      

                 ******                                                                                                        

                   **                                                                                                         

...Program finished with exit code 0                                                                                           

Press ENTER to exit console.

*/
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...