সমস্যা
দেওয়া স্ট্রিং-এ কতগুলো স্বরবর্ণ (vowel) এবং ব্যঞ্জনবর্ণ (consonant) আছে তা গণনা করা।
লজিক
if(str[i]=='A'||'E'||'I'||'O'||'U'||'a'||'e'||'i'||'o'||'u')
vowels++;
else
consonants++;
উদাহরণ প্রোগ্রাম
/* Counting Vowels and Consonants in a String */
#include <stdio.h>
int main() {
char str[100];
int i, vowels, consonants;
i = vowels = consonants = 0;
printf("Enter any String\n : ");
gets(str);
while (str[i] != '\0') {
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')
vowels++;
else
consonants++;
i++;
}
printf("vowels in this String = %d\n", vowels);
printf("consonants in this String = %d", consonants);
return 0;
}
আউটপুট
Enter any String: TutoriasPoint vowels in this String = 6 consonants in this String = 7