C Program to Print K Shape Number Pattern

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

#include <stdio.h>

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

    printf("\nThe K Shape Numbers Pattern\n"); 
    
    for (i = rows; i >= 1; i-- ) 
	{
		for (j = 1 ; j <= i; j++ ) 	
		{
			printf("%d ", j);
		}
		printf("\n");
	}
		
	for (i = 2 ; i <= rows; i++ ) 
	{
		for (j = 1; j <= i; j++ ) 	
		{
			printf("%d ", j);
		}
		printf("\n");
	}
    return 0;
}
C Program to Print K Shape Number Pattern

This C example prints the K shape pattern of numbers or integers using a while loop.

#include <stdio.h>

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

    printf("\nThe K Shape Numbers Pattern\n"); 
    i = rows;

    while( i >= 1 ) 
	{
		j = 1 ;
		while( j <= i ) 	
		{
			printf("%d ", j);
			j++;
		}
		printf("\n");
		i--;
	}

	i = 2 ;
	while ( i <= rows ) 
	{
		j = 1;
		while ( j <= i) 	
		{
			printf("%d ", j);
			j++;
		}
		printf("\n");
		i++;
	}
    return 0;
}
Enter K Shape Numbers Pattern Rows = 11

The K Shape Numbers Pattern
1 2 3 4 5 6 7 8 9 10 11 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 10 11

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

#include <stdio.h>

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

    printf("\nThe K Shape Numbers Pattern\n"); 
    i = rows;

    do
	{
		j = 1 ;
		do 	
		{
			printf("%d ", j);

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

	} while( --i >= 1 );

	i = 2 ;
	do 
	{
		j = 1;
		do 	
		{
			printf("%d ", j);

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

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

The K Shape Numbers Pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
1 2 3 4 5 6 7 8 9 10 11 12 13 
1 2 3 4 5 6 7 8 9 10 11 12 
1 2 3 4 5 6 7 8 9 10 11 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 10 11 
1 2 3 4 5 6 7 8 9 10 11 12 
1 2 3 4 5 6 7 8 9 10 11 12 13 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

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.