Pages

Thursday 11 May 2017

Print the word with odd letters (Asked in Zoho Interview | Set 1 Question 3)

1. Print the word with odd letters as
P         M
 R      A
   O  R
     G
  O    R
 R       A
P          M 

#include<stdio.h>
#include<string.h>
int main()
{
char s[10]="PROGRAM",s1[10];
int l,i,j;
//scanf("%s",&s);
strcpy(s1,s);
//strrev(s1);
l=strlen(s);
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
{
if(i==j)
  printf("%c",s[i]);
else if(i+j==l-1)
  printf("%c",s1[i]);
if(j==l-1)
  printf("\n");
else
  printf(" ");
}
}
return 0;
}

input:

PROGRAM


output:


P      P
 R    R 
  O  O  
   G   
  R  R  
 A    A 
M      M

No comments:

Post a Comment

Code Review

 SOLID Principles S – Single Responsibility Principle There should never be more than one reason for a class to change. O – Open-Closed Prin...