String is a collection of character in other words array of character. In this program we treat string as an array and access each array element and compare it with the vowel character. This program print all the character in a string and count total number of vowel letter. We use string.h libary and strlen() function to get total length and strcmp() to compare each array element with vowel letter. In this example.
Output:
Source Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
int len, i, ch = 0;
char str[50];
clrscr();
printf("Find Number of Vowel Letter in a Word");
printf("\n-----------------------------------------------\n");
printf("Enter a string:");
scanf("%s", str);
len = strlen(str);
i = 0;
printf("\nCharaters in a word\n");
do
{
if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
ch++; //count vowel letter
printf("%c\n", str[i]);
i++;
}while(i < len);
printf("No of letter = %d\t No of vowel = %d", len, ch);
getch();
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
int len, i, ch = 0;
char str[50];
clrscr();
printf("Find Number of Vowel Letter in a Word");
printf("\n-----------------------------------------------\n");
printf("Enter a string:");
scanf("%s", str);
len = strlen(str);
i = 0;
printf("\nCharaters in a word\n");
do
{
if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
ch++; //count vowel letter
printf("%c\n", str[i]);
i++;
}while(i < len);
printf("No of letter = %d\t No of vowel = %d", len, ch);
getch();
}
Output:
No comments:
Post a Comment