Write a program to return the difference between the largest and smallest numbers from an array of positive integer
Answers
Answered by
0
Answer:
Program to find the smallest and largest elements in an array is discussed here. Given an array, the task is to find the largest and smallest elements of the array.
Method 1: Traverse the array iteratively and keep track of the smallest and largest element until the end of the array.
Method 2: Traverse the array recursively and keep track of the smallest and largest element until the end of the array.
Method 3: Sort the array using STL and return the first element as the smallest element and the last element as the largest element.
For example, consider the array.
arr = {1, 2, 3, 4, 5}
Smallest element : 1
Largest element : 5
Explanation:
I HOPE YOU LIKE THIS ANSWER
FOLLOW ME
MARK AS BRAINLEST⭐⭐⭐⭐⭐
Similar questions
Physics,
1 month ago
English,
1 month ago
Business Studies,
2 months ago
Sociology,
2 months ago
Math,
9 months ago