Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
How to store words in an array in C?
Next article icon

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 : 83

Range of Numbers Within an Array in C

To 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.

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.

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; } 

Output
The range of the array is 83:

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


Next Article
How to store words in an array in C?

D

deekshasharma02999
Improve
Article Tags :
  • C Programs
  • C Language
  • c-array
  • C-Arrays
  • C Examples

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
    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
  • How to store words in an array in C?
    We all know how to store a word or String, how to store characters in an array, etc. This article will help you understand how to store words in an array in C. To store the words, a 2-D char array is required. In this 2-D array, each row will contain a word each. Hence the rows will denote the index
    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 curr
    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:
    3 min read
  • Generating Random Numbers in a Range in C
    Write a C program to generate random numbers in a range. Examples Input: min = 5, max = 15Output: 9, 11, 2Explanation: Any integer between 5 and 15 can be the output. Input: min = 0, max = 100Output: 42, 27, 11, 98Explanation: Any integer between 0 and 100 can be the output. Different Ways to Genera
    7 min read
  • How to Iterate Through Array of Structs in C?
    In C, while working with an array of structs we have to iterate through each struct in an array to perform certain operations or access its members. In this article, we will learn how to iterate through an array of the structs in C. Iterate Over of an Array of StructuresTo iterate through an array o
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences