Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- // char data type with array
- char string[120];
- // int data types
- int i, vowels, consonants, digits, spaces;
- // Initial values to 0
- vowels = consonants = digits = spaces = 0;
- printf("\t-: C Program to Count the Number of Vowels, Consonants:- \n\n");
- printf("Enter Any String: ");
- gets(string);
- // First check if any NULL Character given = \0
- for(i=0; string[i] != '\0'; i++)
- {
- if(string[i]=='a' || string[i]== 'e' || string[i]== 'i' ||
- string[i] == 'o' || string[i]== 'u' || string[i]== 'A' ||
- string[i]== 'E' || string[i]== 'I' || string[i]== 'O' || string[i]== 'U')
- {
- // Post-increment
- vowels++;
- }
- else if((string[i] >= 'a' && string[i] <= 'z') || (string[i] >= 'A' && string[i] <= 'Z'))
- {
- // Post-increment
- consonants++;
- }
- else if(string[i] >= '0' && string[i] <= '9')
- {
- // Post-increment
- digits++;
- }
- else if (string[i] == ' ')
- {
- // Post-increment
- spaces++;
- }
- }
- // Print the results
- printf("\n-: The Result is Below :-\n\n");
- printf("Total Vowel(s) Found : %d", vowels);
- printf("\n\nConsonant(s) Found : %d", consonants);
- printf("\n\nDigit(s) Found : %d", digits);
- printf("\n\nWhite Space(s) Found : %d", spaces);
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement