0% found this document useful (0 votes)
4 views

String

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

String

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>
#include <ctype.h> // For tolower() function

int main() {
char str[100];
int vowels = 0, consonants = 0;

// Input the string


printf("Enter a string: ");
fgets(str, sizeof(str), stdin);

// Loop through each character in the string


for (int i = 0; str[i] != '\0'; i++) {
char ch = tolower(str[i]); // Convert to lowercase for easier comparison

// Check if the character is a vowel


if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
vowels++;
}
// Check if the character is a consonant (alphabet but not a vowel)
else if (ch >= 'a' && ch <= 'z') {
consonants++;
}
// Ignore any non-alphabet characters (spaces, punctuation)
}

// Output the results


printf("Vowels: %d\n", vowels);
printf("Consonants: %d\n", consonants);

return 0;
}

You might also like