Breaking

Monday 29 May 2017

Odd Length String Diagonal Pattern [ZOHO]

               Odd Length String Diagonal Pattern [ZOHO]


Image result for zoho logo




An odd length string S of length L is passed as the input.
The program must print the string S as two diagonals as shown in the example  Input/Output below.

Input Format:
The first line will contain S. Output Format: L lines will contain the pattern as shown in the example Input/Output below.

Boundary Conditions: 
Length of S is from 3 to 51.

Example Input/Output 1: 
Input: 
cry

Output:
c y
 r
c y

Example Input/Output 2:
Input:
tiger

Output:
t r
i e
 g
i e
t r

Code:


#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
int i,j,n;
scanf("%s",str);
n=strlen(str);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{

if(j==(n-1-i))
printf("%c",str[n-i-1]);
else if(j==i)
printf("%c",str[j]);
else
printf(" ");
}
printf("\n");

}
return 0;
}

1 comment:

  1. For this same program i got the output but it shows code did not pass the execution in skillrack..why so??

    ReplyDelete

Like