Write a program to count the number of vowels in a string.
Input
#include <stdio.h>
int main()
{
int c = 0, count = 0;
char s[1000];
printf("Input a string : ");
fgets(s,1000,stdin);
while (s[c] != '\0') {
if (s[c] == 'a' || s[c] == 'A' || s[c] == 'e' || s[c] == 'E' || s[c] == 'i' || s[c] == 'I' || s[c] =='o' || s[c]=='O' || s[c] == 'u' || s[c] == 'U')
count++;
c++;
}
printf("Number of vowels in the string : %d\n", count);
return 0;
}
Output
Input a string : I am Dipshikha
Number of vowels in the string : 5
Input
#include <stdio.h>
int main()
{
int c = 0, count = 0;
char s[1000];
printf("Input a string : ");
fgets(s,1000,stdin);
while (s[c] != '\0') {
if (s[c] == 'a' || s[c] == 'A' || s[c] == 'e' || s[c] == 'E' || s[c] == 'i' || s[c] == 'I' || s[c] =='o' || s[c]=='O' || s[c] == 'u' || s[c] == 'U')
count++;
c++;
}
printf("Number of vowels in the string : %d\n", count);
return 0;
}
Output
Input a string : I am Dipshikha
Number of vowels in the string : 5
No comments:
Post a Comment