VOOZH about

URL: https://www.geeksforgeeks.org/c/find-the-range-of-numbers-in-an-array-in-c/

⇱ How to Find the Range of Numbers in an Array in C? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Find the Range of Numbers in an Array in C?

Last Updated : 23 Jul, 2025

The range of numbers within an array is defined as the difference between the maximum and the minimum element present in the array. In this article, we will learn how we can find the range of numbers in an array in C.

Example

Input:
int arr[] = { 23, 12, 45, 20, 90, 89, 95, 32, 65, 19 }

Output:
The range of the array is : 83

Range of Numbers Within an Array in C

To find the range of numbers in an in C, first we have to iterate through an array for find the minimum and the maximum element and then calculate the range which is the difference of maximum and minimum element of an array.

Approach

  • Find the size of the array and store it in a variable n.
  • Declare two variables min and max to find the maximum and minimum value from the array.
  • Initialize both the min and max to the first element of the array.
  • Keep iterating through the rest of the array and update the min and max variables.
  • Find the range of the array by subtracting the value of min from the max.
  • Return the value of range as a result.

C Program to Find the Range of Numbers in an Array

The following program illustrates how we can find the range of numbers in an array in C.


Output
The range of the array is 83:

Time Complexity: O(N), here N is the size of the array.
Auxiliary Space: O(1)

Comment