Problem statement:- Program to remove all numbers from a String
Data requirement:-
Input Data:- str
Output Data:- str
Additional Data:-i, j
Program in C
Output Data:- str
Additional Data:-i, j
Here is the source code of the C Program to remove all numbers from a 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] >= '0' && str[i] <= '9') {
for (j = i; str[j] != '\0'; ++j) {
str[j] = str[j + 1];
}
str[j] = '\0';
}
}
printf("After removing all numbers string is: %s\n",str);
}
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] >= '0' && str[i] <= '9') {
for (j = i; str[j] != '\0'; ++j) {
str[j] = str[j + 1];
}
str[j] = '\0';
}
}
printf("After removing all numbers string is: %s\n",str);
}
Input/Output:
Enter your String:csinfo360
After removing all numbers string is: csinfo
Program in C++
Here is the source code of the C++ Program to remove all numbers from a String.
After removing all numbers string is: csinfo
Program in C++
Here is the source code of the C++ Program to remove all numbers from a 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] >= '0' && str[i] <= '9') {
for (j = i; str[j] != '\0'; ++j) {
str[j] = str[j + 1];
}
str[j] = '\0';
}
}
cout<<"After removing numbers string is: "<<str;
}
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] >= '0' && str[i] <= '9') {
for (j = i; str[j] != '\0'; ++j) {
str[j] = str[j + 1];
}
str[j] = '\0';
}
}
cout<<"After removing numbers string is: "<<str;
}
Input/Output:
Enter your String:program7str8ing
After removing numbers string is: programstring
Program in Java
After removing numbers string is: programstring
Program in Java
Here is the source code of the Java Program to remove all numbers from a String.
Code:
import java.util.Scanner;
public class p35 {
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';
int i,j;
char[] str=str1.toCharArray();
for (i = 0; str[i] != '\0'; ++i) {
while (str[i] >= '0' && str[i] <= '9') {
for (j = i; str[j] != '\0'; ++j) {
str[j] = str[j + 1];
}
str[j] = '\0';
}
}
System.out.println("After removing all numbers string is:");
for (i = 0; str[i] != '\0';i++)
System.out.print(str[i]);
cs.close();
}
}
public class p35 {
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';
int i,j;
char[] str=str1.toCharArray();
for (i = 0; str[i] != '\0'; ++i) {
while (str[i] >= '0' && str[i] <= '9') {
for (j = i; str[j] != '\0'; ++j) {
str[j] = str[j + 1];
}
str[j] = '\0';
}
}
System.out.println("After removing all numbers string is:");
for (i = 0; str[i] != '\0';i++)
System.out.print(str[i]);
cs.close();
}
}
Input/Output:
Enter your String:
Java String99 pro8g0ram
After removing all numbers string is:
Java String program
Java String99 pro8g0ram
After removing all numbers string is:
Java String program
Program in Python
Here is the source code of the Python Program to remove all numbers from a String.
Code:
str=input("Enter the String:")
str2 = []
i = 0
while i < len(str):
ch = str[i]
if not(ch >= '0' and ch <= '9'):
str2.append(ch)
i += 1
Final_String = ''.join(str2)
print("After removing numbers string is:",Final_String)
str2 = []
i = 0
while i < len(str):
ch = str[i]
if not(ch >= '0' and ch <= '9'):
str2.append(ch)
i += 1
Final_String = ''.join(str2)
print("After removing numbers string is:",Final_String)
Enter the String:Csinfo360.com
After removing numbers string is: Csinfo.com
More:-
After removing numbers string is: Csinfo.com
More:-
0 Comments
Please do not Enter any spam link in the comment box