Program to Convert UpperCase to LowerCase

Description

Two way To convert uppercase to lowercase or vice versa  
1) Travese the string character by character add 32 to convert uppercase to
   lowercase and substract 32 to convert lowercase to uppercase.
2) Use the language specific built in function.

C/C++

/* C Program to Convert UpperCase to LowerCase */
//Save it as ConvertUpperToLowerCase.c

/*
  * The ASCII code of a character is stored in the memory not character itself.
  * ASCII values  of alphabets: A – Z is 65 to 90
  * ASCII values  of alphabets: a – z is 97 to 122
  * To convert lower case to upper case, substract 32 from the 
    ASCII value of the character
  * To convert upper case to lower case, add 32 to the 
    ASCII value of the character
*/

#include<stdio.h>
#include<ctype.h>
int main(){

    int i=0;
    char str[100];
    char lowerCase[100];

    printf("Enter a string : ");
    gets(str);

    while(str[i]!='\0'){
        if(str[i]>='A' && str[i]<='Z'){
            lowerCase[i] = (str[i] + 32);
        }
        else{
            lowerCase[i] = str[i];
        }
        i++;
    }
    lowerCase[i]='\0';

    printf("The lowercase of %s is %s\n",str,lowerCase);
	
    /*The library function toupper() and tolower() is used to convert a
      character into upper or lower respectively. */
    //It is defined in ctype.h
    int j = 0;
    char ch;

    printf("The lowercase of %s is ",str);
    while (str[j]) {
        ch = str[j];
        putchar(tolower(ch));
        j++;
    }

    /*The library function strupr() and strlwr() is used to convert a
      character into upper or lower respectively. */	
    strlwr(str);
    printf("The lowercase is %s ",str);

    return 0;
}

Output

Input:
Enter a string : Sachin Kumar
Output:
The lowercase of Sachin Kumar is sachin kumar

Java

/* Java Program to Convert UpperCase to LowerCase */
//Save it as ConvertUpperToLowerCase.java

/*
 1) toLowerCase() convert a string to lowercase.
 2) toUpperCase() convert a string to uppercase.
*/

import java.io.*;
import java.util.Scanner;
public class ConvertUpperToLowerCase {
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str;  
        System.out.println("Enter a string : ");
        str = scanner.nextLine();
        System.out.println("The lowercase of "+str+" is "+str.toLowerCase());
    }
}

Output

Input:
Enter a string : 
Sachin Kumar
Output:
The lowercase of Sachin Kumar is sachin kumar

Related Programs

1) Program to Convert Lowercase to Uppercase of a String
2) Program to count uppercase and lowercase alphabet characters in String
3) Program to check String is Palindrome
4) Program to sort characters of strings in alphabetical order
5) Program to Sort set of strings in alphabetical order
6) Program to remove vowels from a String
7) Program to Multiply Numbers Present in a String
8) Program to remove given number from a string
9) Program to Replace Spaces With Dots
10) Find Occurrence Of Each Word In a Sentence
11) Print All Unique Words Of A String
Share Me

Leave a Reply