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

Lower Case To Upper Case


()

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

 

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote Count

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

READ  Word Break
Array Interview Questions
Graph Interview Questions
LinkedList Interview Questions
String Interview Questions
Tree Interview Questions