Convert Uppercase to lowercase without using string function

Problem statement:- Program to Convert Uppercase to lowercase without using the inbuilt function.

Sample Input/Output:-


Sample Input First:

CSINFO360.COM

Sample Output First: 

csinfo360.com

Sample Input Second: 

CSINFO 360 COM

Sample Output Second: 

csinfo 360 com


Data requirement:-

   Input Data:- str

  Output Data:-str

  Additional Data:- i

Program in C

Here is the source code of the C Program to Convert Uppercase to lowercase without using the inbuilt function.

Code:

#include <stdio.h>
#include <string.h>
int main()
{
  char str[30];
  printf("Enter your String(Upper case):");
  scanf("%[^\n]"str);
  int i = 0;
  //convert capital letter string to small letter string
  while (str[i] != '\0')
  {
    if (str[i] > 64 && str[i] < 91//or if(str[i]>='A' && str[i]<='Z')
      str[i] += 32;
    i++;
  }
  printf("Lower case String is:%s"str);
}


Input/Output:
Enter your String(Upper case):CSINFO360.COM
Lower case String is:csinfo360.com


Program in C++

Here is the source code of the C++ Program to Convert Uppercase to lowercase without using the inbuilt function.

Code:

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
  string str;
  cout << "Enter your String(Upper case):";
  getline(cin, str);
  int i = 0;
  //convert capital letter string to small letter string
  while (str[i] != '\0')
  {
    if (str[i] > 64 && str[i] < 91//or if(str[i]>='A' && str[i]<='Z')
      str[i] += 32;
    i++;
  }
  cout << "Lower case String is: " << str;
}


Input/Output:
Enter your String(Upper case):CSINFO 360 COM
Lower case String is: csinfo 360 com

Program in Java

Here is the source code of the Java Program to Convert Uppercase to lowercase without using the inbuilt function.

Code:

import java.util.Scanner;

public class UppercaseToLowercase{

    public static void main(String[] args) {
        Scanner cs = new Scanner(System.in);
        String strstr2 = " ";
        char c = ' ';
        System.out.println("Enter your String(Upper case):");
        str = cs.nextLine();
        str += '\0';
        int i = 0;
        // convert capital letter string to small letter string
        while (str.charAt(i) != '\0') {
            if (str.charAt(i) > 64 && str.charAt(i) < 91)// or if(str.charAt(i)>='A' && str.charAt(i)<='Z')
                c = (char) (str.charAt(i) + 32);
            else
                c = (char) (str.charAt(i));
            str2 += c;
            i++;
        }
        System.out.println("Lower case String is: " + str2);
        cs.close();
    }
}

Input/Output:
Enter your String(Upper case):
csinfo360
Lower case String is: csinfo360

Program in Python

Here is the source code of the Python Program to Convert Uppercase to lowercase without using the inbuilt function.

Code:

str = input("Enter the String(Upper case):")
i = 0
ch2 = ''
# convert capital letter string to small letter string
while str[i:]:
    ch = ord(str[i])
    if ch > 64 and ch < 91:
        ch2 += chr(ch+32)
    else:
        ch2 += chr(ch)
    i += 1
print("Lower case String is:"ch2)


Input/Output:

Post a Comment

0 Comments