Rhombus Pattern – N Slashes Side

              Rhombus Pattern – N Slashes Side


Given an odd value of N, the program must print a rhombus in diamond shape whose side contains N slashes as shown below in the examples.

Input Format:
The first line contains N.

Output Format:
The rhombus in diamond shape with each side containing N slashes. Asterisk 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,flag=1,flag1=1;
x=n-1;
y=n;
for(i=0;i<n;i++)
    {
        for(j=0;j<n*2;j++)
            {
              if(x==j&&flag1==1)
                {
                    cout<<“/”;
                    x–;
                    flag1=0;
                }
            else if(y==j&&flag==1)
                {
                    cout<<“\”;
                    y++;
                    flag=0;
                }
            else
               cout<<“*”;
            }
            cout<<“n”;
        flag=1,flag1=1;
    }
    x=0;y=n*2-1;
    flag=1;flag1=1;
    for(i=0;i<n;i++)
        {
            for(j=0;j<n*2;j++)
                {
                    if(x==j&&flag==1)
                    {
                        cout<<“\”;
                        x++;
                        flag=0;
                    }
                    else if(y==j&&flag1==1)
                        {
                            cout<<“/”;
                            y–;
                            flag1=0;
                        }
                    else
                        cout<<“*”;
                }
                cout<<“n”;
            flag=1;flag1=1;
        }

}
2 Comments

Add a Comment

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