Pages

Monday, September 5, 2016

C program to print special alphabet pattern.


/*C program to print special alphabet pattern.
For n=5,
            A
          A B A
        A B C B A
      A B C D C B A
    A B C D E D C B A
*/

#include<stdio.h>
int main()
{
     int i, j, k, n;
     printf("Enter number of lines to be printed:");
     scanf("%d", &n);
     for (i=0; i<n; i++)
     {
           //logic for intial spaces
           for(j=0; j<=n-i; j++)
                printf("  ");

           //logic for priting Alphabets
           for(k=0; k<=i; k++)
                printf("%c ", 64+k+1);
          
           for(j=i; j>0; j--)
                printf("%c ", 64+j);
          
           printf("\n");
     }
     return 0; 
}


Output of the Program:

Enter number of lines to be printed:5
            A
          A B A
        A B C B A
      A B C D C B A
    A B C D E D C B A


2 comments: