Google News
logo
C++ Program to Convert Uppercase to Lowercase
In the following example of C++ program to convert uppercase letters to lowercase :
Program :
#include <iostream>
#include <string>

using namespace std;

int main() {
    string str;

    cout << "Enter a string in uppercase: ";
    getline(cin, str);

    for (int i = 0; i < str.length(); i++) {
        if (str[i] >= 'A' && str[i] <= 'Z') {
            str[i] = str[i] + 32;
        }
    }

    cout << "The string in lowercase is: " << str << endl;

    return 0;
}
Output :
Enter a string in uppercase: FREETIMELEARNING.COM
The string in lowercase is: freetimelearning.com
This program prompts the user to enter a string in uppercase, reads the input string using getline(), and then uses a for loop to iterate through each character in the string.

If the character is an uppercase letter (ASCII value between 65 and 90), it is converted to lowercase by adding 32 to its ASCII value. The modified string is then printed to the console.