/* Erik Ferguson Assignment 7 11.19.2000 */ // === Includes =============================================================== #include // === Includes =============================================================== // === Function Initializations =============================================== void PrintArray(int[], int); // prints the array int SumArray(int[], int, int); // prints the sum of the first 10 values int sequential_search(int search_key, int list_size, const int array_to_search[]); // searches an array int DelElement(int[], int, int); // deletes an element int InsElement(int[], int, int, int); // adds an element // *** Function Initializations *********************************************** // *** main ******************************************************************* int main() { // Variable Declarations int a[20] = {14,17,23,26,33,38,39,41,52,56,0,0,0,0,0,0,0,0,0,0}; int i, sum, n = 10, NumEls = 10, // total number of elements in array a DeleteIndex, // index of number to delete after searched InsertIndex = 3, // index of number to insert at NumToInsert = 7, // number to insert at InsertIndex x = 38; // number to delete // Print out original value of a printf("\nArray at start of program:\n"); PrintArray(a, NumEls); // Sum up the first n elements and output sum = SumArray(a, n, NumEls); printf("\nSum of the first %d elements: %d",n,sum); // Find the index of the number to delete, which is variable x DeleteIndex = sequential_search(x, NumEls, a); // If the index is not -1, the default value of index, then delete if(DeleteIndex != -1) { // Delete the element... store return value of list_size in NumEls NumEls = DelElement(a, DeleteIndex, NumEls); // Print out new array after deletion printf("\n\nAfter deletion of %d:\n", x); PrintArray(a, NumEls); } // end if(DeleteIndex != -1) else printf("\n%d Not found in array a[]! Deletion failed.\n", x); // Insert the element and store return value of list_size in NumEls NumEls = InsElement(a, NumToInsert, InsertIndex, NumEls); printf("\n\nAfter insertion of %d at index %d:\n", NumToInsert, InsertIndex); PrintArray(a, NumEls); return 0; } // end main // *** main ******************************************************************* // === FUNCTION DEFINITIONS =================================================== // *** PrintArray ************************************************************* // Function to print the first NumEls elements of array b void PrintArray(int b[], int NumEls) { int i = 0; printf("Array a has %d elements: ",NumEls); for(i=0;i