Pyramid pattern || Full pyramid || patterns || special characters || C++

In this, we are going to see how to print the above pattern of Triangle of Multiple special characters, using nested for loops in C++.


The code given below can be used for TURBO C++ Compiler:-

// pattern 19
 #include <iostream.h>
 #include<conio.h>  

 void main()  
 {  
    clrscr();
    int i,j,k,l,n;    
    cout<<"Enter the Range\n";    
    cin>>n;    
    for(i=1;i<=n;i++)    
    {    
        for(j=1;j <=n-i;j++)    
        {    
            cout<<" ";    
        }    
        for(k=1;k <=i;k++)    
        {
            if(i%2==0)
            {
              cout<<"#";
            }
            else
            cout<<"&";
        }    
        for(l=i-1;l>=1;l--)    
        {
           if(i%2==0)
            {
              cout<<"#";
            }
            else
            cout<<"&";
        }    
        cout<<"\n";    
    }    
 getch();
 }
  
    

The code given below can be used for g++/gcc Compiler:-

// pattern 19
 #include <iostream>
 using namespace std;  

 int main()  
 {  
    int i,j,k,l,n;    
    cout<<"Enter the Range\n";    
    cin>>n;    
    for(i=1;i<=n;i++)    
    {    
        for(j=1;j <=n-i;j++)    
        {    
            cout<<" ";    
        }    
        for(k=1;k <=i;k++)    
        {
            if(i%2==0)
            {
              cout<<"#";
            }
            else
            cout<<"&";
        }    
        for(l=i-1;l>=1;l--)    
        {
           if(i%2==0)
            {
              cout<<"#";
            }
            else
            cout<<"&";
        }    
        cout<<"\n";    
    }    
 return 0;  
 }
  
    
#ENJOY CODING


 

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post