I am trying to create a C program function called \"compare_arrays\" in order to
ID: 3771668 • Letter: I
Question
I am trying to create a C program function called "compare_arrays" in order to compare two integer arrays of the same SIZE = 26 (26 because each space represents a character from the alphabet). One array holds a count of how many letters a specific word has. The second array holds the count of letters a user inputs. I am trying to see given the letters entered if I am able to spell that specific word.
I am not sure if I am headed in the right direction.... I am having trouble with the loops..
int compare_arrays(int dictionary[], int user[])
{
int j; // counter to go through arrays
for (j = 0; user[j] >= dictionary[j]; j++)
{
if (user[j] == '')
{
return 1; // you are able to spell the word with the given letters
}
}
else
{
return 0; // you are not able to spell the word with the given letters
}
}
Explanation / Answer
int compare_arrays(int dictionary[], int user[],int m ,int n)
{
for(int i=0;i<m;i++)
{
for (j = 0; j<n; j++)
{ if(user[i] >= dictionary[j])
{ if (user[j] == '')
{
return 1; // you are able to spell the word with the given letters
}
else
{
return 0; // you are not able to spell the word with the given letters
}
}
}
}
here m and n denotes the length of the array dictionary and user and I have passed it as arguements to the function and performed the same task.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.