C Program to Print K Shape Alphabets Pattern

Write a C program to print K shape alphabets pattern using for loop.

#include <stdio.h>

int main()
{
    int i, j, rows, alphabet;
    
    printf("Enter K Shape Alphabets Pattern Rows = ");
    scanf("%d",&rows);

    printf("\nThe K Shape Alphabets/Characters Pattern\n"); 
    
    for (i = rows - 1; i >= 0; i-- ) 
	{
		alphabet = 65;
		for (j = 0 ; j <= i; j++ ) 	
		{
			printf("%c ", alphabet + j);
		}
		printf("\n");
	}
		
	for (i = 1 ; i < rows; i++ ) 
	{
		alphabet = 65;
		for (j = 0 ; j <= i; j++ ) 	
		{
			printf("%c ", alphabet + j);
		}
		printf("\n");
	}
    return 0;
}
C Program to Print K Shape Alphabets Pattern

This C example prints a K shape pattern of alphabets using a while loop.

#include <stdio.h>

int main()
{
    int i, j, rows, alphabet;
    
    printf("Enter K Shape Alphabets Pattern Rows = ");
    scanf("%d",&rows);

    printf("\nThe K Shape Alphabets/Characters Pattern\n");

	i = rows - 1;
	
	while (i >= 0 ) 
	{
		alphabet = 65;
		j = 0 ;
		while ( j <= i) 	
		{
			printf("%c ", alphabet + j);
			j++;
		}
		printf("\n");
		i--;
	}
		
	i = 1 ;
	while ( i < rows ) 
	{
		alphabet = 65;
		j = 0 ;
		while ( j <= i ) 	
		{
			printf("%c ", alphabet + j);
			j++;
		}
		printf("\n");
		i++;
	} 
    return 0;
}
Enter K Shape Alphabets Pattern Rows = 8

The K Shape Alphabets/Characters Pattern
A B C D E F G H 
A B C D E F G 
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 
A B C D E F G 
A B C D E F G H

C Program to display a K shape alphabets pattern using a do while loop.

#include <stdio.h>

int main()
{
    int i, j, rows, alphabet;
    
    printf("Enter K Shape Alphabets Pattern Rows = ");
    scanf("%d",&rows);

    printf("\nThe K Shape Alphabets/Characters Pattern\n");

	i = rows - 1;
	
	do
	{
		alphabet = 65;
		j = 0 ;
		do	
		{
			printf("%c ", alphabet + j);

		} while ( ++j <= i) ;
		printf("\n");

	} while (--i >= 0 );
		
	i = 1 ;
	do 
	{
		alphabet = 65;
		j = 0 ;
		do	
		{
			printf("%c ", alphabet + j);

		} while ( ++j <= i );
		printf("\n");

	} while ( ++i < rows );
    return 0;
}
Enter K Shape Alphabets Pattern Rows = 12

The K Shape Alphabets/Characters Pattern
A B C D E F G H I J K L 
A B C D E F G H I J K 
A B C D E F G H I J 
A B C D E F G H I 
A B C D E F G H 
A B C D E F G 
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 
A B C D E F G 
A B C D E F G H 
A B C D E F G H I 
A B C D E F G H I J 
A B C D E F G H I J K 
A B C D E F G H I J K L 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.