- 1
How to print string pattern taking inputâHELLO Output: H H HE HE HEL HEL HELL HELL HELLOHELL
3 Answers
0
This works. The output doesn't look correct in the console on the playground in this app but on a PC it's the right number of spaces: Edited: to get the user's input from the console.
static void Main(string[] args)
{
Console.Write("Enter a string: ");
string hello = Console.ReadLine();
int size = hello.Length;
for (int i = 0; i <= size; i++) {
Console.Write(hello.Substring(0, i));
int numSpaces = (size-i) * 2;
for (int j = 0; j < numSpaces; j++) {
Console.Write(" ");
}
Console.WriteLine(hello.Substring(0,i));
}
}
0
h