Search This Blog

Showing posts with label Programming question. Show all posts
Showing posts with label Programming question. Show all posts

Program to Display String with Odd Number of Letters in the shape of letter 'X' - Zoho Programming Test Question

One of the previous questions in the programming round of Zoho recruitment process was to write a C program to display any string with odd number of letters as follows, in the shape of letter 'X'.

Print the word with odd number of letters as
P         M
 R      A
   O  R
     G
  O    R
 R       A
P          M 



#include<stdio.h> #include<string.h> #include<stdlib.h> void main() { int n,i,j,k,l; char str[20]; printf("Enter a string with odd number of letters."); scanf("%s",str); if((n=strlen(str))%2==0)     {     printf("\nNot odd");     exit(0);     } for(i=0;i<n;i++)     {     printf("\n");     for(j=0;j<n;j++)         {         if(i==j||j==n-1-i)             printf("%c",str[j]);         else             printf(" ");         }     } }