How to Find the Range of Numbers in an Array in C? Last Updated : 20 Jun, 2024 Comments Improve Suggest changes Like Article Like Report 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 : 83Range of Numbers Within an Array in CTo find the range of numbers in an array 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. ApproachFind 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 ArrayThe following program illustrates how we can find the range of numbers in an array in C. C // C Program to Find the Range of Numbers in an Array #include <stdio.h> int main() { // Initialize an array int arr[] = { 23, 12, 45, 20, 90, 89, 95, 32, 65, 19 }; // Finding size of an array int n = sizeof(arr) / sizeof(arr[0]); // Intialize the first element of the array as both // maximum and minimum value int min = arr[0]; int max = arr[0]; // Find the maximum and minimum value in the array for (int i = 1; i < n; i++) { if (max < arr[i]) max = arr[i]; if (min > arr[i]) min = arr[i]; } // Calculating the range of an array int range = max - min; // Printing the range of an array printf("The range of the array is %d:", range); return 0; } OutputThe range of the array is 83:Time Complexity: O(N), here N is the size of the array.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Find the Range of Numbers in an Array in C? D deekshasharma02999 Follow Improve Article Tags : C Programs C Language c-array C-Arrays C Examples +1 More Similar Reads How to Find the Mode of Numbers in an Array in C? In C, the mode of array numbers is the element that appears most frequently in the array. To find the mode, we can count the occurrences of each element and identify the one with the highest count. In this article, we will find the mode of numbers in C. Example:Input: myArray = { 1, 2, 3, 4, 5, 2, 3 5 min read How to Find the Mode of Numbers in a Sorted Array in C? The mode of the given numbers can be defined as the value that occurs the most in the given dataset or the value with the highest frequency. In this article, we will learn how to find the mode of all elements in a sorted array of integers in C. Example: Input:myArray = {1, 2, 3, 3, 5, 5, 5, 5, 6, 7} 2 min read How to Find the Size of an Array in C? The size of an array is generally considered to be the number of elements in the array (not the size of memory occupied in bytes). In this article, we will learn how to find the size of an array in C.The simplest method to find the size of an array in C is by using sizeof operator. First determine t 2 min read How to Find Maximum Value in an Array in C? In C, arrays are data structures that allow the user to store a collection of data of the same type. In this article, we will learn how we can find the maximum value in an array in C. Example Input: arr = {5,3,1,2,4} Output: The maximum value of the array is: 5Finding Maximum Value in an Array in CW 2 min read C Program to Find the Maximum and Minimum Element in the Array In this article, we will discuss different ways to find the maximum and minimum elements of the array in C.The simplest method to find the maximum and minimum element of the array is iterates through the array and compare each element with the assumed minimum and maximum and update them if the curre 3 min read How to Find Size of Dynamic Array in C? In C, dynamic memory allocation allows us to manage memory resources during the execution of a program. Itâs particularly useful when dealing with arrays where the size isnât known at compile time. In this article, we will learn how to find the size of a dynamically allocated array in C. Find Size o 2 min read C Program to Sort an Array in Ascending Order Sorting an array in ascending order means arranging the elements in the order from smallest element to largest element.The easiest way to sort an array in C is by using qsort() function. This function needs a comparator to know how to compare the values of the array. Let's look at a simple example:C 3 min read C Program to Find Minimum Value in Array In this article, we will learn how to find the minimum value in the array.The easiest and straightforward method is to iterate through each element of the array, comparing each value to an assumed minimum and updating it if the current value is less.C#include <stdio.h> int findMin(int arr[], i 3 min read How to Initialize Array to 0 in C? Initializing an array to zero is a common practice in programming to ensure that all elements start with a known value. In C, there are several ways to initialize an array to zero. In this article, we will explore different methods to do so. Initialize Array to 0 in CThere are mainly two ways to ini 2 min read C Program To Find Prime Numbers Between Given Range A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 2, 3, 5, 7, and 11 are prime numbers. In this article, we will learn how to find all the prime numbers between the given range.ExampleInput: l = 10, r = 30Output: 11 13 17 19Explanat 6 min read Like