Program Discussion :: Strings
59 / 60
Write a program to enter the string then delete the vowels from string.
Answer:
#include
#include
#include
using namespace std;
int check_vowel(char);
int main()
{
char s[100], t[100];
int i, j = 0;
cout
Asked In ::
Language:
Ashok
20 Jun, 2017 10:39 PM
<!DOCTYPE html>
<html>
<body>
<?php
function Remove_vowel() {
$arr ="what is your name"; /* input string */
echo "Input string is :" . $arr."<br/>";
$arrc=array(); $j=0; /* initialising an empty array and its initial index */
$arrlength=strlen($arr);
for($x=0; $x< $arrlength; $x++) /* loop for reading the input array */
{
/* comparing each character with vowels */
if( ($arr[$x]=="a")||($arr[$x]=="e")||($arr[$x]=="i")||($arr[$x]=="o")||($arr[$x]=="u"))
{
continue ; /* for repeating the loop and skipping the below statement */
}
else
{
$arrc[$j]=$arr[$x]; /* adding character without vowels into different array */
$j++;
}
}
$name= implode ("",$arrc); /* conversion of array into string */
echo $name; /* printing string without vowels */
}
Remove_vowel();
?>
</body>
</html>
Language:
Shyam
7 Jul, 2017 9:30 AM
#include <stdio.h>
#include <string.h>
int check_vowel(char);
int main()
{
char s[100], t[100];
int i, j = 0;
printf("Enter a string to delete vowels\n");
gets(s);
for(i = 0; s[i] != '\0'; i++) {
if(check_vowel(s[i]) == 0) { //not a vowel
t[j] = s[i];
j++;
}
}
t[j] = '\0';
strcpy(s, t); //We are changing initial string
printf("String after deleting vowels: %s\n", s);
return 0;
}
int check_vowel(char c)
{
switch(c) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
return 1;
default:
return 0;
}
}
Language:
Nick
7 Jul, 2017 9:30 AM
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int check_vowel(char);
int main()
{
char s[100], t[100];
int i, j = 0;
cout<<"Enter a string to delete vowels\n";
gets(s);
for(i = 0; s[i] != '\0'; i++) {
if(check_vowel(s[i]) == 0) { //not a vowel
t[j] = s[i];
j++;
}
}
t[j] = '\0';
strcpy(s, t); //We are changing initial string
cout<<"String after deleting vowels: %s\n";
return 0;
}
int check_vowel(char c)
{
switch(c) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
return 1;
default:
return 0;
}
}
Language:
Jaykumar
25 Aug, 2017 12:42 AM
import java.util.Scanner;
class DeleteVowel
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the input");
String str=sc.nextLine();
String result=str.replaceAll("[aeiouAEIOU]","");
System.out.println("After removed vowel:- "+result);
}
}
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
import java.io.*;
public class DeleteVowels
{
public static void main(String[] args)throws IOException
{
String str1=""; //New string which will contain no vowels.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String: ");
String str=br.readLine(); //Initial string containing vowel.
int len = str.length();
for(int i=0;i<len;i++)
{
char ch=str.charAt(i);
if((ch=='A')||(ch=='E')||(ch=='I')||(ch=='O')||(ch=='U')||(ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u'))
continue;
else
str1=str1+ch;
}
System.out.println("String after removing vowels: "+str1);
}
}