Silahkan Melihat Tutorial di website kami dengan nyaman ENJOY YOUR LIFE ☕

Character Pattern of Half Diamond

Q. Write a C program to print the following design of Character Pattern of Half Diamond as:

          D

          CDC
          BCDCB
          ABCDCBA
          BCDCB
          CBC
          D

Ans.


/*c program for character pattern of half diamond*/
#include<stdio.h>
int main()
{
 char ch,r,c,p,q,z;
 printf("Enter seed character : ");
 scanf("%c", &ch);
 if(ch>='a' && ch<='z')
    ch=ch-32;
 printf("\n\n");
 for(r='A',z=ch; r<=ch; r++,z--)
 {
    for(c=r,p=z; c>='A'; c--,p++)
        printf("%c",p);
    for(c=r,p=ch-1; c>'A'; c--,p--)
        printf("%c",p);
    printf("\n");
 }
 for(r='A',z=ch-1; r<ch; r++,z--)
 {
    for(c=r,p=r+1; c<ch; c++,p++)
        printf("%c",p);
    for(c=z,p=ch-1; c>'A'; c--,p--)
        printf("%c",p);
    printf("\n");
 }
 getch();
 return 0;
}


/****************************************************************

The output of above character pattern of half diamond would be:
***************************************************************/
Output of Character Pattern of Half Diamond C program
Figure: Screen shot for Character Pattern of Half Diamond C Program


Related Programs:
1. Number pattern of Half Diamond C program
          4
          343
          23432
          1234321
          23432
          343
          4


You might also like to read:
  1. Big list of 98+ C Pyramid Programs
  2. Latest user asking Pyramid program list




0 komentar:

Post a Comment

Character Pattern of Half Diamond