2.05.2016

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

3 comments:

  1. *
    *A*
    *A*B*
    *A*B*C*

    can you post soluion for this ?

    ReplyDelete
    Replies
    1. #include
      #include
      int main()
      {
      int i,j,m;
      for(i=1;i<=5;i++)
      {
      printf("*");
      m=65;
      for(j=1;j<i;j++)
      {
      printf("%c*",m++);
      }
      printf("\n");
      }
      return 0;
      }

      Delete
  2. #include
    #include
    int main()
    {
    int i,j,m;
    for(i=1;i<=5;i++)
    {
    m=65;
    for(j=1;j<=i*2-1;j++)
    {
    if(j%2==0)
    printf("%c",m++);
    else
    printf("*");
    }
    printf("\n");
    }
    return 0;
    }

    ReplyDelete