Multi Layered Diamond Shaped Rhombus Pattern

Multi Layered Diamond Shaped Rhombus Pattern

Given an odd value of N, the program must print multi layered rhombus pattern in diamond shapes whose side contains N, N-2, … 1 slashes respectively as shown below in the examples.
Input Format:
The first line contains N.
Output Format:
The  multi layered rhombus pattern in diamond shapes whose side contains N, N-2, … 1 slashes respectively. Hash symbol is used as a filler for other values.
Boundary Conditions:
1 <= N <= 101 and N is odd.
Example Input/Output 1:
Input:
5
Output:
####/####
###/#####
##/#/###
#/#/####
/#/#/##
##/#/#/
####/#/#
###/#/##
#####/###
####/####
Example Input/Output 2:
Input:
11
Output:
##########/##########
#########/###########
########/#/#########
#######/#/##########
######/#/#/########
#####/#/#/#########
####/#/#/#/#######
###/#/#/#/########
##/#/#/#/#/######
#/#/#/#/#/#######
/#/#/#/#/#/#####
#####/#/#/#/#/#/
#######/#/#/#/#/#
######/#/#/#/#/##
########/#/#/#/###
#######/#/#/#/####
#########/#/#/#####
########/#/#/######
##########/#/#######
#########/#/########
###########/#########
##########/##########

Code:

#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
    int n,i,j;
    cin>>n;
    int x,y,f=1,f1=1,f2=1;
    x=n-1;
    y=n;
    char  arr[n*2][n*2];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n*2;j++)
        {
            if(x==j&&f==1)
                {
                    //cout<<“/”;
                    arr[i][j]=’/’;
                    x–;
                    f=0;
                }
            else if(y==j&&f1==1)
                {
                    arr[i][j]=’\’;
                    //cout<<“\”;
                        y++;
                        f1=0;
                }
                else
                    arr[i][j]=’#’;
                    //cout<<“#”;
            if(f2==0&&f1!=0)
            if(i>1)
            {
                arr[i][j]=arr[i-2][j];
            }
            if(f==0)
                f2=0;
        }
        f=1;f1=1;f2=1;
      
          
      
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n*2;j++)
        {
            cout<<arr[i][j];
    }
    cout<<“n”;
}
for(i=n-1;i>=0;i–)
    {
        for(j=0;j<n*2;j++)
        {
            if(arr[i][j]==’#’)
            cout<<“#”;
            else if(arr[i][j]==’/’)
                cout<<“\”;
            else
                cout<<“/”;
        }
        cout<<“n”;
    }

}


Execute code Here:

4 Comments

Add a Comment

Your email address will not be published. Required fields are marked *