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

 


Next > < Prev
Scroll to Top