C Program to Print the K Shape Character Pattern for given string

Write a program to print the K shape character pattern for the given string

Input Format

The input contains a string

Output Format
Print the k-shape character pattern

Constraint
1<=Length<=10Sample Input 1

ABCDEF

Sample Output 1

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

Sample Input 2

FINE

Sample Output 2

F I N E 
F I N 
F I 
F 
F 
F I 
F I N 
F I N E 

Code:

#include<stdio.h>
#include<string.h>
int main()
{
    char n[100];
    scanf("%s",n);
    for(int i =0; n[i] !='\0';i++)
    {
        for(int j=0;j<strlen(n)-i;j++) printf("%c ",n[j]);
        printf("\n");
    }

    for(int i =0; n[i] !='\0';i++)
    {
        for(int j=0;j<i+1;j++) printf("%c ",n[j]);
        printf("\n");
    }
}
Code language: C/AL (cal)

Leave a Comment