Next Time Read Comma Again Using Consonant Plus Vowel Linking

C plan to count the full number of vowels and consonants in a string – In this article, nosotros will discuss the multiple means to count the total number of vowels and consonants in a string in C programming.

Suitable examples and sample programs have also been added and then that yous can understand the whole thing very clearly. The compiler has as well been added with which you tin execute information technology yourself.

The ways mentioned in this piece are equally follows:

  • Using Standard Method
  • Using Office
  • Using Recursion
  • Using Pointers and While Loop

A cord is nil but an array of characters. The value of a cord is adamant by the terminating character. Its value is considered to be 0.

C Program Count Number Of Vowels & Consonants In A String

Firstly, you need to enter a string whose vowels and consonants y'all need to determine.

Here, the string "how-do-you-do earth" is entered.

Equally you can see, at that place are:

Vowels: 3

Consonants: 7

Hence, the numbers will be printed accordingly.

Thus, the different methods to do and so in C programming are every bit follows:

Using Standard Method

  1. Read the entered cord and store the string into the variable 's' using gets(south) office.

2)For loop iterates through string 's' with the structure for(i=0;s[i];i++),

a)If the ASCII value of s[i] is in the range of 65 to 90 or 97 to 122 then check s[i] is equal to any ane of the vowels(a,e,i,o,u).If due south[i] is equal to whatever vowel then increase the vowel count, otherwise increment the consonant count.

Echo this step up to end of the string.

three)Impress the number of vowels and consonants present in the cord.

Output:

Using Function – Count Total No of Vowels & Consonants

  1. The main() calls the stringcount() part, passing the string as an argument to the function.

ii)The office stringcount(char *s) counts the number of vowels and consonants nowadays in the string.

a)The office checks the each character's ASCII value is inside the range of alphabets or not.

b)If the character is an alphabet then it compares the character with vowels. If the character is a vowel then increase the vowel count, otherwise increase the consonant count.

These a,b steps will be repeated upwardly to finish of the cord using for loop with the construction for(i=0;s[i];i++).

three)The function stringcount(char *s) prints the vowels count and consonant count.

Output:

Using Recursion

  1. The main() function calls the stringcount(char *s) function by passing the string equally an statement.

2)The part stringcount(char *s)

initialize vowels=0,consonants=0.

a)If due south[i] is null then print the vowels count and consonants count.

b)if due south[i] is not cipher so check southward[i] is an alphabet or not, based on ASCII value.

b.one)If s[i] is an alphabet then compare southward[i] with vowels if information technology is a vowel then increment the vowel count otherwise increase the consonant count.

b.2)i value volition be increased by 1. The part calls itself.

The function calls itself recursively upward to s[i] is equal to nil.

Output:

Using Pointers And While Loop
  1. p is the pointer variable which points the cord s.

2)While loop checks first character of the string existed or non.If information technology has existed and then check information technology is an alphabet or not.

a)If information technology has existed then check it is alphabet or not. If information technology is an alphabet then bank check it is vowel or consonant. If it is a vowel and then increase the vowel count otherwise increase the consonant count.

b)Increment the p count, then pointer variable points the next graphic symbol of the cord. Then check the while condition for the next character of the string.

Repeat until the graphic symbol at pointer variable p becomes nix.

3)Print the vowels count and consonants count.

Output:

dyesquished1991.blogspot.com

Source: https://javatutoring.com/c-program-count-vowels-consonants-in-string/

0 Response to "Next Time Read Comma Again Using Consonant Plus Vowel Linking"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel