From 5fe25c39787853e2582429d6dd9040189ee5bf15 Mon Sep 17 00:00:00 2001 From: AngadOnTop Date: Tue, 7 Oct 2025 15:20:25 +1100 Subject: [PATCH] added count_vowels.c --- count_vowels.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 count_vowels.c diff --git a/count_vowels.c b/count_vowels.c new file mode 100644 index 0000000..64d5a2f --- /dev/null +++ b/count_vowels.c @@ -0,0 +1,26 @@ +#include + +// Program to count vowels in a string +int main() { + char str[100]; + int i, count = 0; + + // Ask the user to enter a string + printf("Enter a string: "); + fgets(str, sizeof(str), stdin); // safer input method than gets() + + // Loop through the string + for (i = 0; str[i] != '\0'; i++) { + // Check for both uppercase and lowercase vowels + if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || + str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || + str[i] == 'O' || str[i] == 'U') { + count++; + } + } + + // Display the total number of vowels + printf("Number of vowels: %d\n", count); + + return 0; +}