Zoho Second round question - X Form String
Print the word with odd letters as
P M
R A
O R
G
O R
R A
P M
Print in X form
C++ Program:
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
string s;
cin >> s;
int n = s.length();
for(int i = 0; i<=(n-1)/2;i++)
{
if(i!=n-1-i)
{
for(int j=0;j<i;j++)
{cout<<" ";}
cout<<s[i];
for(int j=i+1;j<n-i;j++)
{cout<<" ";}
cout<<s[n-1-i];
cout<<"\n";
}
else
{
for(int j=0;j<i;j++)
{cout<<" ";}
cout<<s[i]<<"\n";
}
}
int k =(n-1)/2;
int m = (n-1)/2;
int l=(n-1)/2;
for(int i = 0; i<=(n-1)/2;i++)
{
m=m-1;
l=l+1;
for(int j=0;j<m;j++)
{
cout<<" ";
}
cout<<s[m];
for(int j=m;j<l;j++)
{cout<<" ";}
cout<<s[l];
cout<<"\n";
}
getch();
return 0;
}
Comments
Post a Comment