Write a program to convert Uppercase to LowerCase
Last Updated :
15 Feb, 2024
Write a program to convert Uppercase to LowerCase
Examples:
Input: str= “GEEKSFORGEEKS”
Output: “geeksforgeeks”
Input: str= “CAT”
Output: “cat”
Approach:
Iterate through each character in a string and add 32 in the ASCII value of each character.
- ASCII value of lowercase char ‘a’ to ‘z’ ranges from 97 to 122
- ASCII value of uppercase char ‘A’ to ‘Z’ ranges from 65 to 92
- For conversion add 32 in the ASCII value of input char
Below is the implementation of the above approach:
C++
#include <iostream>
using namespace std;
int main() {
string str= "GEEKSFORGEEKS" ;
string ans= "" ;
for ( int i=0;i<str.size();i++){
ans+=str[i] +32 ;
}
cout<<ans;
}
|
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String str = "GEEKSFORGEEKS" ;
String ans = "" ;
for ( int i = 0 ; i < str.length(); i++) {
ans += Character.toLowerCase(str.charAt(i));
}
System.out.println(ans);
}
}
|
Python3
str_input = "GEEKSFORGEEKS"
ans = ""
for char in str_input:
ans + = char.lower()
print (ans)
|
C#
using System;
class Program
{
static void Main()
{
string str = "GEEKSFORGEEKS" ;
string ans = "" ;
for ( int i = 0; i < str.Length; i++)
{
ans += char .ToLower(str[i]);
}
Console.WriteLine(ans);
}
}
|
Javascript
let str = "GEEKSFORGEEKS" ;
let ans = "" ;
for (let i = 0; i < str.length; i++) {
ans += str[i].toLowerCase();
}
console.log(ans);
|
Time Complexity: O(N)
Auxiliary space: O(1)
Related Article:
Share your thoughts in the comments
Please Login to comment...