Home » Technical Interview Questions » String Interview Questions » Lower Case To Upper Case

Lower Case To Upper Case


Reading Time - 1 mins

Given a string with only lower case letters, write a function that will print the same string but with upper case letters

Example

INPUT
s = “tutorial cup”

OUTPUT
“TUTORIAL CUP”

Algorithm

1. For every charcater in the string, do s[i] – ‘a’ + ‘A’

C++ Program

#include <bits/stdc++.h>
using namespace std;

//This function converts all the lower case characters into upper case characters
void lowerToUpper(string s)
{
	int n = s.length();
	for (int i = 0; i < n; ++i)
	{
		if ('a' <= s[i] <= 'z')
		{
			s[i] = s[i] - 'a' + 'A';
		}
	}
	cout<<s<<endl;
}
int main()
{
	string s = "tutorial cup";
	lowerToUpper(s);
}

Try It

 

READ  Find the Closest Palindrome number
Array Interview Questions
Graph Interview Questions
LinkedList Interview Questions
String Interview Questions
Tree Interview Questions