Functions and Recursions – Arithmetic – Problem #8

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: medium

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

Back to Lab Problems
Functions and Recursions/Arithmetic/Problem #8

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #8

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.