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:
**********/\**********
*********/**\*********
********/****\********
*******/******\*******
******/********\******
*****/**********\*****
****/************\****
***/**************\***
**/****************\**
*/******************\*
/********************\
\********************/
*\******************/*
**\****************/**
***\**************/***
****\************/****
*****\**********/*****
******\********/******
*******\******/*******
********\****/********
*********\**/*********
**********\/**********
C code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=0;i<2*n;i++)
{
for(j=0;j<2*n;j++)
{
if(i<n)
{
if(j==n-1-i)
printf("/");
else if(j==n+i)
printf("\\");
else
printf("*");
}
else
{
if(j==i-n)
printf("\\");
else if(j==2*n-(i-n)-1)
printf("/");
else
printf("*");
}
}
printf("\n");
}
}
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:
**********/\**********
*********/**\*********
********/****\********
*******/******\*******
******/********\******
*****/**********\*****
****/************\****
***/**************\***
**/****************\**
*/******************\*
/********************\
\********************/
*\******************/*
**\****************/**
***\**************/***
****\************/****
*****\**********/*****
******\********/******
*******\******/*******
********\****/********
*********\**/*********
**********\/**********
C code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=0;i<2*n;i++)
{
for(j=0;j<2*n;j++)
{
if(i<n)
{
if(j==n-1-i)
printf("/");
else if(j==n+i)
printf("\\");
else
printf("*");
}
else
{
if(j==i-n)
printf("\\");
else if(j==2*n-(i-n)-1)
printf("/");
else
printf("*");
}
}
printf("\n");
}
}
No comments:
Post a Comment