CREATE OWN LIBRARY

Print Characters Vertically

Back to Programming

Description

Print the characters vertically starting from left to right of the string:

 

A string can be defined as an array of characters. Here, the program is written to print the characters vertically starting from left to right of the string. Each character of the string is printed in separate lines. For example, if the string is “abc” then, this string is containing three letters (or characters)- ‘a’, ‘b’, ‘c’. Now, this letter will be printed in three separate lines vertically as:

            A

            B

            C 

If the characters are in small letters, it will then be converted into upper case and then the upper case characters should be printed. To print the characters like this, first, each character is accessed according to the index position of them (the index starts from 0), if it is in lower case will be converted into upper case and will be printed, and after printing each character the cursor should be moved to the next line and again the next character will be printed. This process will be continued till the last character of the string.

Algorithm

INPUT: A string
OUTPUT: The characters printed vertically.
PROCESS:
Step 1: [Taking the input]
	Read s [‘s’ is the string]
Step 2: [printing the characters vertically]
	 For i=0 to length(s)-1 repeat
		[if the character is in lower case]
		If s[i]≥'a' and s[i]≤'z' then
			Set s[i]<-s[i]-32
		[End of ‘if’]
		Print  s[i]
		Move to the next line
	[End of ‘for’ loop]
Step 3: Stop.

Code

Time Complexity:

The time complexity of this program is- O(n) where n is the number of characters of the string.

 

Space Complexity:

The space complexity of this program is O(n) where n is the number of characters of the string

Contributed by