C Programming: Convert vowels into upper case character in a given string
34. Uppercase Vowels in String
Write a C program to convert vowels into uppercase characters in a string.
Sample Solution:
C Code:
#include <stdio.h>
int main() {
char string1[255]; // Declaring a character array to store the sentence
int i;
printf("Input a sentence: ");
gets(string1); // Input a sentence and store it in string1
printf("The original string:\n");
puts(string1); // Print the original sentence
i = 0;
// Loop through the string until the end of the string ('\0') is reached
while (string1[i] != '\0') {
// Convert lowercase vowels to uppercase by subtracting 32 from their ASCII values
if (string1[i] == 'a' || string1[i] == 'e' || string1[i] == 'i' || string1[i] == 'o' || string1[i] == 'u') {
string1[i] = string1[i] - 32;
}
i++; // Move to the next character in the string
}
printf("After converting vowels into uppercase, the sentence becomes:\n");
puts(string1); // Print the modified sentence with uppercase vowels
return 0;
}
Output:
Input a sentence: The original string: w3resource After converting vowels into upper case the sentence becomes: w3rEsOUrcE
Flowchart:
For more Practice: Solve these Related Problems:
- Write a C program to traverse a string and convert every vowel to its uppercase form.
- Write a C program to modify a string so that only the vowels are changed to uppercase while consonants remain unchanged.
- Write a C program to convert vowels to uppercase using a switch-case statement for each character.
- Write a C program to iterate through a string and replace lowercase vowels with their uppercase counterparts using ASCII manipulation.
C Programming Code Editor:
Improve this sample solution and post your code through Disqus.
Previous C Exercise: Count of each character in a given string.
Next C Exercise: Length of the longest substring in a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics