Here is a program to count number of vowels present in an entered sentence.
Logic: Here variable ‘vowels’ is incremented whenever a vowel found in tracing. Logic behind this is very simple, that comparing each character to the set of vowels, predefined in an array. If this character is in the set of vowels then it implies that character is a vowel, so we increment the count by one.
Same logic can be applied to find the existence of any letter set in the predetermined array.
int vowels = 0, i = 0;
printf(“\n\n\t ENTER A STRING…: “);
while(str[i] != ‘\0′)
if(str[i]==’A’ || str[i]==’a’ || str[i]==’E’ || str[i]==’e’ || str[i]==’I’ || str[i]==’i’ ||
str[i]==’O’ || str[i]==’o’ || str[i]==’U’ || str[i]==’u')
printf(“\n\n\t THE TOTAL NUMBER OF VOWELS IS…: %d”, vowels);
Download exe and source code here.
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
Copyright©2012 electrofriends.com All Rights Reserved