Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to declare an array of character and initialize it to a string.

ID: 3812828 • Letter: W

Question

Write a program to declare an array of character and initialize it to a string. The program should display the count of times that each vowel appears in the string. Also, it should display the vowel that appeared the most. To do these things you should write two functions as follows. Write a function to count the number of each vowel character in that string. The function should count the number of characters a, o, u, i and e in that string. Main should pass the string as well as an integer array of size 5. Each location of this array will contain the number of one of the vowels. The main program should print the number of vowels that the function place in the array. Write another function that determines the max value of an array. Pass the array, the size, the addresses of two other variables called index and value. The function should find the max value and the index of the max value and place them in location index and value. ( C language )

Explanation / Answer


// C code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void countVowel(char ch[], int count[])
{
int l = strlen(ch);
for (int i = 0; i < l; ++i)
{

if(ch[i] == 'a')
count[0]++;
else if(ch[i] == 'e')
count[1]++;
else if(ch[i] == 'i')
count[2]++;
else if(ch[i] == 'o')
count[3]++;
else if(ch[i] == 'u')
count[4]++;
}
}


void maximum(int count[], int size, int *index, int *value)
{
*index = 0;
*value = count[0];

for (int i = 0; i < 5; ++i)
{
if(count[i] > *value)
{
*value = count[i];
*index = i;
}
}
}

int main()
{
char ch[] = "jaamesanderson is the best bowler in world";
int count[5] = {0};

countVowel(ch,count);

printf("Count of 'a': %d ",count[0]);
printf("Count of 'e': %d ",count[1]);
printf("Count of 'i': %d ",count[2]);
printf("Count of 'o': %d ",count[3]);
printf("Count of 'u': %d ",count[4]);

int index, value;

maximum(count,5,&index,&value);

printf(" Maximum count: %d Index: %d ",value,index);

return 0;
}

/*
output:

Count of 'a': 3
Count of 'e': 5
Count of 'i': 2
Count of 'o': 3
Count of 'u': 0

Maximum count: 5
Index: 1


*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote