1. Print the word with odd letters as
P M R A O R G O R R A P M
Solution:
using System;
public class Test
{
public static void Main()
{
string text = Console.ReadLine();
int n=text.Length;
Pattern print = new Pattern ();
print.XPattern(text,n);
}
}
public class Pattern
{
public void XPattern(string text,int n)
{
char[] textarray = text.ToCharArray();
int reverseprinter = n-1;
int middleLetter = n/2;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j && j!=middleLetter)
{
Console.Write(textarray[j]);
}
else if(j==reverseprinter)
{
Console.Write(textarray[reverseprinter]);
reverseprinter--;
}
else
{
Console.Write("*");
}
}
Console.WriteLine();
}
}
}
OUTPUT
Please Enter text:INPUT : programp m r a o r g o r r a p m
Comments
Post a Comment