Problem statement:- Program to Print vowels in a string.
Data requirement:-
Input Data:- str
Output Data:-str
Output Data:-str
Additional Data:- i
Program in C
Here is the source code of the C Program to Print vowels in a string.
Code:
#include<stdio.h>
#include<string.h>
int main()
{
char str[30];
printf("Enter your String:");
scanf("%[^\n]",str);
int i;
printf("All the vowels in the string are:\n");
for(i=0;i<strlen(str);i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e'|| str[i]=='E' || str[i]=='i'
|| str[i]=='I' || str[i]=='o' || str[i]=='O' || str[i]=='u' || str[i]=='U')
{
printf("%c ",str[i]);
}
}
}
#include<string.h>
int main()
{
char str[30];
printf("Enter your String:");
scanf("%[^\n]",str);
int i;
printf("All the vowels in the string are:\n");
for(i=0;i<strlen(str);i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e'|| str[i]=='E' || str[i]=='i'
|| str[i]=='I' || str[i]=='o' || str[i]=='O' || str[i]=='u' || str[i]=='U')
{
printf("%c ",str[i]);
}
}
}
Input/Output:
Enter your String:csinfo com
All the vowels in the string are:
i o o
All the vowels in the string are:
i o o
Program in C++
Here is the source code of the C++ Program to Print vowels in a string.
Code:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string str;
cout<<"Enter your String:";
getline(cin,str);
int i=0;
int len=0;
while(str[len]!='\0')
{
len++;
}
cout<<"All the vowels in the string are:\n";
for(i=0;i<len;i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e'|| str[i]=='E' || str[i]=='i'
|| str[i]=='I' || str[i]=='o' || str[i]=='O' || str[i]=='u' || str[i]=='U')
{
cout<<str[i]<<" ";
}
}
}
#include<cstring>
using namespace std;
int main()
{
string str;
cout<<"Enter your String:";
getline(cin,str);
int i=0;
int len=0;
while(str[len]!='\0')
{
len++;
}
cout<<"All the vowels in the string are:\n";
for(i=0;i<len;i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e'|| str[i]=='E' || str[i]=='i'
|| str[i]=='I' || str[i]=='o' || str[i]=='O' || str[i]=='u' || str[i]=='U')
{
cout<<str[i]<<" ";
}
}
}
Input/Output:
Enter your String:string program
All the vowels in the string are:
i o a
All the vowels in the string are:
i o a
Program in Java
Here is the source code of the Java Program to Print vowels in a string.
Code:
import java.util.Scanner;
public class p12 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str1;
System.out.println("Enter your String:");
str1=cs.nextLine();
char[] str=str1.toCharArray();
System.out.print("All the vowels in the string are:");
for(int i=0;i<str1.length();i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e'|| str[i]=='E' || str[i]=='i'
|| str[i]=='I' || str[i]=='o' || str[i]=='O' || str[i]=='u' || str[i]=='U')
{
System.out.print(str[i]+" ");
}
}
cs.close();
}}
public class p12 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
String str1;
System.out.println("Enter your String:");
str1=cs.nextLine();
char[] str=str1.toCharArray();
System.out.print("All the vowels in the string are:");
for(int i=0;i<str1.length();i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e'|| str[i]=='E' || str[i]=='i'
|| str[i]=='I' || str[i]=='o' || str[i]=='O' || str[i]=='u' || str[i]=='U')
{
System.out.print(str[i]+" ");
}
}
cs.close();
}}
Input/Output:
Enter your String:
java string program
All the vowels in the string are:a a i o a
java string program
All the vowels in the string are:a a i o a
Program in Python
Here is the source code of the Python Program to Print vowels in a string.
Code:
str=input("Enter the String:")
for i in range(len(str)):
if str[i] == 'a' or str[i] == 'A' or str[i] == 'e' or str[i] == 'E' or str[i] == 'i'or str[i] == 'I' or str[i] == 'o' or str[i] == 'O' or str[i] == 'u' or str[i] == 'U':
print(str[i],end=" ")
for i in range(len(str)):
if str[i] == 'a' or str[i] == 'A' or str[i] == 'e' or str[i] == 'E' or str[i] == 'i'or str[i] == 'I' or str[i] == 'o' or str[i] == 'O' or str[i] == 'u' or str[i] == 'U':
print(str[i],end=" ")
Input/Output:
Enter the String:Python string program
o i o a
o i o a
0 Comments
Please do not Enter any spam link in the comment box