Que: Write a program to count the number of vowels in a given string
Vowels : a,e,i,o,u
Code:
#include <stdio.h>
int main()
{
int c = 0, count = 0;
char s[1000];
printf("\nInput a string\n");
gets(s);
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("\nNumber of vowels in the string: %d\n", count);
return 0;
}
Output:
Vowels : a,e,i,o,u
Code:
#include <stdio.h>
int main()
{
int c = 0, count = 0;
char s[1000];
printf("\nInput a string\n");
gets(s);
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("\nNumber of vowels in the string: %d\n", count);
return 0;
}
Output:
No comments:
Post a Comment