Given string str, the task is to convert all the vowels present in the given string to uppercase characters in the given string.
Examples:
Input: str = “GeeksforGeeks”
Output: GEEksfOrGEEks
Explanation:
Vowels present in the given string are: {‘e’, ‘o’}
Replace ‘e’ to ‘E’ and ‘o’ to ‘O’.
Therefore, the required output is GEEksfOrGEEks.Input: str = “eutopia”
Output: EUtOpIA
Approach: The idea is to iterate over the characters of the given string and check if the current character is a lowercase character and a vowel or not. If found to be true, convert the character to its uppercase. Follow the steps below to solve the problem:
- Traverse the given string and check if str[i] is a lowercase vowel or not.
- If found to be true, replace str[i] to (str[i] – ‘a’ + ‘A’).
- Finally, after complete the traversal of the string, print the final string.
Below is the implementation of the approach:
C++
// C++ program to implment// the above approach#include <bits/stdc++.h>using namespace std;// Function to convert vowels// into uppercasestring conVowUpp(string& str){ // Stores the length // of str int N = str.length(); for (int i = 0; i < N; i++) { if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u') { str[i] = str[i] - 'a' + 'A'; } } return str;}// Driver Codeint main(){ string str = "eutopia"; cout << conVowUpp(str);} |
Java
// Java program to implment// the above approachimport java.util.*;class GFG{// Function to convert vowels// into uppercasestatic void conVowUpp(char[] str){ // Stores the length // of str int N = str.length; for (int i = 0; i < N; i++) { if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u') { char c = Character.toUpperCase(str[i]); str[i] = c; } } for(char c : str) System.out.print(c);}// Driver Codepublic static void main(String[] args){ String str = "eutopia"; conVowUpp(str.toCharArray());}}// This code is contributed by 29AjayKumar |
Python3
# Python3 program to implement# the above approach# Function to convert vowels# into uppercasedef conVowUpp(str): # Stores the length # of str N = len(str) str1 ="" for i in range(N): if (str[i] == 'a' or str[i] == 'e' or str[i] == 'i' or str[i] == 'o' or str[i] == 'u'): c = (str[i]).upper() str1 += c else: str1 += str[i] print(str1)# Driver Codeif __name__ == '__main__': str = "eutopia" conVowUpp(str)# This code is contributed by Amit Katiyar |
C#
// C# program to implment// the above approachusing System;class GFG{// Function to convert vowels// into uppercasestatic void conVowUpp(char[] str){ // Stores the length // of str int N = str.Length; for (int i = 0; i < N; i++) { if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u') { char c = char.ToUpperInvariant(str[i]); str[i] = c; } } foreach(char c in str) Console.Write(c);}// Driver Codepublic static void Main(String[] args){ String str = "eutopia"; conVowUpp(str.ToCharArray());}}// This code is contributed by shikhasingrajput |
EUtOpIA
Time Complexity: O(N)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

