Exercise Write a program that gets a set of characters from the user and stores
ID: 2250237 • Letter: E
Question
Exercise Write a program that gets a set of characters from the user and stores them in an array chars ]. The program stops when the number of characters is greater than 10 or ## is entered, whichever comes first. Then the program performs the following tasks: 1. Displays the array using a user defined function that has the following prototype void dispArray (char x[], int N); 2. Computes the count of vowels (lower or upper cases) using a user-defined function named findSum Vols() with the following prototype int findNumVols (char x[], int N); In addition, this function calls another user-defined function named isVowel) to check each element of its input array if it is vowel or not. The function isVowe1( returns 1 if its input is a vowel character and 0 otherwise and has the following prototype: int isVowel (char ch);Explanation / Answer
Answer:- The code is written below-
#include<stdio.h>
void dispArray(char *, int );
int fidNumVols(char *, int );
int isVowel(char ch);
int main(void)
{
char ch_arr[10], char_in[2];
int loop_cnt, ch_arr_size, vowel_cnt = 0;
printf("Enter the characters:");
for(loop_cnt =0; loop_cnt < 10; loop_cnt++)
{
scanf("%c", &char_in[0]);
scanf("%c", &char_in[1]);
if(char_in[0] == '#' && char_in[1] == '#' )
{
break;
}
ch_arr[loop_cnt] = char_in[0];
}
ch_arr_size = loop_cnt;
dispArray(ch_arr, ch_arr_size);
for(loop_cnt = 0; loop_cnt < ch_arr_size; loop_cnt++)
{
vowel_cnt += isVowel(ch_arr[loop_cnt]);
}
printf(" Number of vowels = %d ", vowel_cnt);
return 0;
}
void dispArray(char x[], int N)
{
int loop_cnt;
printf("The entered characters are:");
for(loop_cnt = 0; loop_cnt<N; loop_cnt++)
{
printf("%c ", x[loop_cnt]);
}
}
int isVowel(char ch)
{
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' ) {
return 1;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.