- 1

How to print string pattern taking input→HELLO Output: H H HE HE HEL HEL HELL HELL HELLOHELL

15th Oct 2016, 7:14 AM
Tanuj Patra
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)); } }
15th Oct 2016, 6:27 PM
Darren Moody
Darren Moody - avatar
0
h
21st Nov 2016, 5:51 AM
Ahmed Darbka
Ahmed Darbka - avatar
21st Jul 2020, 1:15 AM
shubham kumar
shubham kumar - avatar