C Program to Print Alphabet Flip Triangle Pattern

Write a Program to print the below pattern for the given input number.

Constraints

1 <= input <=9
 Sample Input 1

5

Sample Output 1

A B C D E D C B A 
   B C D E D C B 
      C D E D C 
         D E D 
            E 

Code:

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int c=0;
    int m=n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<i*2;j++)
        {
            printf(" ");
        }
        int k=i;
        for(int j=0;j<(2*m)-1;j++)
        {
            if(k == n) k--;
            if(j<m){
                printf("%c ",65+k);
                k++;
            }
            else{
                k--;
                printf("%c ",65+k);
                
            }
            
        }

        m=m-1;
        printf("\n");
    }
}
Code language: C/AL (cal)

Leave a Comment