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

Counting Vowels and Consonants in A Given Line of Text

This C program counts the vowels and consonants in a user-input string. It uses scanf to take input, stores it in a character array str, then iterates through str using a for loop. If the character is a vowel, it increments the vow counter. If it is not a space, it increments the cons counter. It then prints the input string, total vowels, and total consonants.

Uploaded by

arunkumar116
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

Counting Vowels and Consonants in A Given Line of Text

This C program counts the vowels and consonants in a user-input string. It uses scanf to take input, stores it in a character array str, then iterates through str using a for loop. If the character is a vowel, it increments the vow counter. If it is not a space, it increments the cons counter. It then prints the input string, total vowels, and total consonants.

Uploaded by

arunkumar116
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

/* Counting vowels and consonants in a given line of text */ #include<stdio.h> #include<string.

h> int main() { char str[80]; int i,vow=0,cons=0; printf("Enter a string : "); scanf("%[ ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr stuvwxyz]",str); for (i = 0; i < strlen(str); i++) 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') vow++; else if (str[i] != ' ') // Ignore BLANK characters cons++; printf("\n\nThe given string is %s",str); printf("\n\nThe total number of VOWELS in a given string is %d",vow); printf("\nThe total number of CONSONANTS in a given string is %d",cons); return 0; } /* End of Main */

You might also like