For this assignment, you will write a C program with several functions that manipulate arrays, including strings (which are null-terminated arrays of chars).

Like the last assignment:

Your function prototypes should match the ones I give here. Your main function should call each of your other functions. The purpose of your main function is to convince you that your other functions are working properly. I don’t care about the details of your main; for instance, I don’t care whether it includes a dialog with the user.

  • unsigned maxValue( const unsigned a[], unsigned elements ); If elements is 0, complain and die. Return the value of the largest element.
  • unsigned maxIndex( const unsigned a[], unsigned elements ); If elements is 0, complain and die. Return the index of the largest element. If there is a tie for which element is largest, return the index of the first occurrence of the largest value. e.g., maxIndex( {3, 5, 2, 5}, 4 should return 1, not 3.
  • void reverse( unsigned a[], unsigned elements ); Reverse the order of the elements. For instance, reverse would change {1, 2, 4} to {4, 2, 1}.
  • int allSame( const unsigned a[], const unsigned b[], unsigned elements ); a and b are parallel arrays, each with elements elements. Return whether all the elements in a have the same value as the corresponding elements in b. For instance, allSame( {1,2,3}, {1,2,3}, 3) returns 1. allSame( {1,2,3}, {1,3,2}, 3 ) returns 0. allSame( {}, {}, 0 ) return 1.
  • void sum( unsigned partialSum[], const unsigned a[], unsigned elements ); partial sum and a are parallel arrays, each with elements elements. sum’s job is, for each i, to set partialSum[i] to a[0] + a[1] + ... + a[i]. For instance, if a were {1, 2, 3, 4}, then sum would set partialSum to {1, 3, 6, 10}.
  • unsigned howMany( char c, const char * s ); howMany returns how many times the char c appears in the string s before the terminating null char. For instance, howMany( ‘t’, “Tattletale” ) returns 3. howMany( ‘I’, “team” ) returns 0. howMany( ‘’, “” ) returns 0.
  • int anagram( const char * a, const char * b ); anagram returns whether the string b has the chars the same number of times (though not necessarily in the same order) as b. For instance, anagram( “stop”, “spot” ) returns 1. anagram( “stop”, “spots” ) returns 0. anagram( “spots”, “spott” ) returns 0. anagram( “stop”, “stop” ) returns 1. anagram( “”, “” ) returns 1. anagram (“logarithm”, “algorithm” ) returns 1.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.