C Programming: Convert vowels into upper case character in a given string
C String: Exercise-34 with Solution
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;
}
Sample Output:
Input a sentence: The original string: w3resource After converting vowels into upper case the sentence becomes: w3rEsOUrcE
Flowchart :
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming-exercises/string/c-string-exercise-34.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics