1 Write a program to generate a rhombus shape of user define

1. Write a program to generate a rhombus shape of user defined length and character. A rhombus is a parallelogram with four equal sides. Here, length of the side means how many characters are used to create each side. For example, here is a rhombus of side length 6 built with character ‘*’. Your program should ask the user for the length of the side and the character to use.

Solution

PROGRAM:

#include<stdio.h>
int main()
{
   int n,i,j,ch;
   char s;
   printf(\"enter row number:\"); //entering the number of rows in which the rhombus have to be printed
   scanf(\"%d\",&n);
   printf(\"enter some character: \"); //entering some special character(single). Might be !,@,#,$,%,^,&,* etc.
   scanf(\" %c\",&s);
   for(i=1;i<=n;i++)
   {
       for(ch=n-i;ch>=1;ch--)
       {
           printf(\" \"); //printing number of white spaces in a row
       }
       for(j=1;j<=i;j++)
       {
           printf(\"%c\",s); //printing special character in a column
       }
       for(j=i-1;j>=1;j--)
       {
           printf(\"%c\",s);
       }
       printf(\"\ \");
   }
   for(i=1;i<=n;i++)
   {
       for(ch=i;ch>=1;ch--)
       {
           printf(\" \");
       }
       for(j=1;j<=(n-i);j++)
       {
           printf(\"%c\",s);
       }
       for(j=(n-i-1);j>=1;j--)
       {
           printf(\"%c\",s);
       }
       printf(\"\ \");
   }
   return 0;
}

OUTPUT:

enter row number:3

enter some character:*

*

***

*

NOTE:

Any special characters can be used.

  

1. Write a program to generate a rhombus shape of user defined length and character. A rhombus is a parallelogram with four equal sides. Here, length of the sid
1. Write a program to generate a rhombus shape of user defined length and character. A rhombus is a parallelogram with four equal sides. Here, length of the sid

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site