Remove all uppercase characters in the String

Problem statement:-  Program to Remove all uppercase characters in the String 

 Data requirement:-

   Input Data:- str

  Output Data:- str or Final_String (In Python)

  Additional Data:-i, j or str2 in Python

Program in C

Here is the source code of the C Program to Remove all uppercase characters in the String.

Code:

#include<stdio.h>
int main()
{
    char str[30];
    printf("Enter your String:");
    scanf("%[^\n]",str);
    int i,j;

     for (i = 0; str[i] != '\0'; ++i) {
     while (str[i] >= 'A' && str[i] <= 'Z') {
         for (j = i; str[j] != '\0'; ++j) {
            str[j] = str[j + 1];
         }
         str[j] = '\0';
      }
   }
       printf("After removing uppercase letter string is: %s\n",str);
}

Input/Output:
Enter your String:CsInfo DoT
After removing uppercase letter string is: snfo o

Program in C++

Here is the source code of the C++ Program to Remove all uppercase characters in the String.

Code:

#include<iostream>
using namespace std;
int main()
{
    string str;
    cout<<"Enter your String:";
    getline(cin,str);
    int len=0;
    while(str[len]!='\0')
    {
        len++;
    }
    int i,j;

     for (i = 0; str[i] != '\0'; ++i) {
     while (str[i] >= 'A' && str[i] <= 'Z') {
         for (j = i; str[j] != '\0'; ++j) {
            str[j] = str[j + 1];
         }
         str[j] = '\0';
      }
   }
       cout<<"After removing uppercase letter string is: "<<str;
}

Input/Output:
Enter your String:PrOgraM
After removing uppercase letter string is: rgra

Program in Java

Here is the source code of the Java Program to Remove all uppercase characters in the String.

Code:

import java.util.Scanner;
public class p32 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str1;
System.out.println("Enter your String:");
str1=cs.nextLine();
str1+='\0';
char[] str=str1.toCharArray();
int i,j;
for (i = 0; str[i] != '\0'; ++i) {
     while (str[i] >= 'A' && str[i] <= 'Z') {
         for (j = i; str[j] != '\0'; ++j) {
            str[j] = str[j + 1];
         }
         str[j] = '\0';
      }
   }
System.out.println("After removing uppercase letter string is: ");
for (i = 0; str[i] != '\0';i++)
System.out.print(str[i]);
    cs.close();
}
}

Input/Output:
Enter your String:
JavA StrInG PrOgRam
After removing uppercase letter string is: 
av trn rgam

Program in Python

Here is the source code of the Python Program to Remove all uppercase characters in the String.

Code:

str=input("Enter the String:")
str2 = []
i = 0
while i < len(str):
    ch = str[i]
    if not ch.isupper():
        str2.append(ch)
    i += 1
Final_String = ''.join(str2)
print("After removing uppercase letter string is:",Final_String)

Input/Output:
Enter the String:CsInFo
After removing uppercase letter string is: sno

More:-

C/C++/Java/Python Practice Question 


Post a Comment

0 Comments