New Post:

Top Resume Builder in 2k21

Pattern printing Middle Letter- odd length string-Skillrack

Pattern printing Middle Letter- odd length string

 Pattern printing Middle Letter- odd length string
                           Image result for skillrack

An odd length string S is passed as the input. The program must print the pattern as described below.
Let L be the length of the string and M denote the middle position of the string S. The characters in the string are a(1),...., a(M), .... a(L).- The first line will contain the middle letter a(M) of S in the extreme right.- Then in each subsequent line, the letters after the middle letter from a(M+1) to a(L) is appended to the line output.- After the end of the string a(L) is reached, in each subsequent line, the letters from the beginning to the middle letter, a(1) to a(M-1) are appended to the line output.
Note: Asterisk * will be used to pad in the front so that each line has L characters

Input Format:
The first line will contain S.

Output Format:
L lines as output where L is the length of the string S.
Boundary Conditions:3 <= L <= 1001
Example:
 Input/Output 1:

Input:
CRY

Output:
**R
*RY
RYC

Example Input/Output 2:
Input:
PROG
.........
CODE:

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k,x=0;
    char str[1001];
    scanf("%s",str);
    int len=strlen(str);
    int mid=len/2;
        for(i=len;i>0;i--)
        {
            for(j=0;j<i;j++)
            {
            if(x+j<=len-2)
                printf("* ");
              
            for(k=0;k<=x;k++)
            {
                 if(x+j>len-2&&x+j<=len)
                if(mid+k>len-1)
                    printf("%c ",str[(mid+k)-len]);
                else
                printf("%c ",str[mid+k]);
            }
            }
            printf("\n");
            x++;
        }
    return 0;
}

Just Give Your Feedback ConversionConversion EmoticonEmoticon