Functions and Recursions – Arithmetic – Problem #8
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Take an integer array as input from the user. Write a recursive function to find the absolute difference of the consecutive two elements in that array from beginning to end of the array. To solve this problem, you need to write 2 functions: Function-1 computes the absolute difference between 2 numbers and returns the same. Function-2 is a recursive function which computes the successive differences between the elements of an array from beginning to end of an array. Function-2 uses the Function-1 for calculating the difference between 2 numbers, and it should take only the integer array and its size as input arguments. Example: Enter the number of elements of the array: 6 Enter a number: 12 Enter a number: 23 Enter a number: 34 Enter a number: 45 Enter a number: 56 Enter a number: 67 The absolute difference of 12 and 23 is: 11 The absolute difference of 23 and 34 is: 11 The absolute difference of 34 and 45 is: 11 The absolute difference of 45 and 56 is: 11 The absolute difference of 56 and 67 is: 11