Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program arrays1.c that checks if two integer arrays are different by one and only one element when compared element by element (first element
Write a program arrays1.c that checks if two integer arrays are different by one and only one element when compared element by element (first element with first element, second with second, and so on) and displays the elements that are different . The program asks the user to enter the size of the arrays and then the elements of the arrays.
Project 4, Program Design 1. (50 points) Write a program arrays1.c that checks if two integer arrays are different by one and only one element when compared element by element (first element with first element, second with second, and so on) and displays the elements that are different. The program asks the user to enter the size of the arrays and then the elements of the arrays. Sample input/output #1: Enter the length of the array: 5 Enter the elements of the first array: -12 0 4 2 36 Enter the elements of the second array: -12 0 4 5 36 Output: The arrays are different by one element, 2 and 5. Sample input/output #2: Enter the length of the array: 4 Enter the elements of the first array: -12 0 4 36 Enter the elements of the second array: -12 0 4 36 Output: The arrays are NOT different by one element Sample input/output #3: Enter the length of the array: 5 Enter the elements of the first array: 5 0 4 2 36 Enter the elements of the second array: -12 0 4 5 36 Output: The arrays are NOT different by one element 1) Include and implement the following function in the program. Do not modify the function prototype. int one_element_different (int *al, int *a, int n, int *elementi, int *element2); The function takes two integer array parameter al and a2 of size n. The function returns 1 if the two arrays are different one and only one element, returns 0 otherwise. elementi and element2 are integer pointers pointing to the variables in the main function that store the elements of the array 1 and array 2 where the elements are different. The function should use pointer arithmetic - not subscripting - to visit array elements. In other words, eliminate the loop index variables and all use of the Il operator in the function. 2) In the main function, ask the user to enter the size of the arrays, declare the arrays, and then ask the user to enter the elements of the two arrays. The main function calls one_element_different function, and displays the result. 2. (50 points) Write a program that adds the first and last elements of an integer array and stored as the first element of the output array, adds the second and second-to-last elements and stored as the second number, and so on. If the array has an odd number of integers, leave the central integer in the original array unchanged. Sample input/output #1: Enter the length of the array: 7 Enter the elements of the array: 3 5 8 4 1 39 Output: 12 8 9 4 Sample input/output #2: Enter the length of the array: 6 Enter the elements of the array: 2 6 13 4 1 7 Output: 9 7 17 1) Name your program arrays2.c 2) Include the following function compute() in the program: void compute(int *al, int ni, int *a2, int n2); al represents the input array with length n1, and a2 represents the output array with length n2. The function should use pointer arithmetic, not subscripting to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function. 3) In the main function, ask the user to enter the length of the input array, declare the input array, calculate the length of the output array, declare the output array, call the compute function, and display the output arrayStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started