Monday 27 March 2017

Array Range

QUESTION DESCRIPTION 

Write a program to find the range of the elements in the array.

Range of an array is the difference between the maximum and minimum element in an array,

Input and Output Format:

Input consists of n+1 integers where n corresponds to the number of elements in the array.

The first integer corresponds to n and the next n integers correspond to the elements in the array.

Output consists of an integer which corresponds to the range of the array.

Assume that the maximum number of elements in the array is 20.

Refer sample input and output for formatting specifications.

All text in bold corresponds to input and the rest corresponds to output.


TEST CASE 1

INPUT

5
1 2 4 3 5

OUTPUT

The range of the array is:4


EXPLANATION : 

The code requires you find the range of the elements of the array ( range : max element - min element )

ALGORITHM : 

  • Accept the number of elements from user ( n )
  • Accept the numbers from the user 
  • Check for the largest and smallest number ( arr[i] > max , arr[i] < min )
  • Calculate the range ( max-min )
  • Print the result with appropriate message

SOLUTION : (Please use this as reference only)

CODE


No comments:

Post a Comment