
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Print missing elements that lie in range 0 – 99
It will display the missing values from the given set entered by the user
Given : array = {88, 105, 3, 2, 200, 0, 10}; Output : 1 4-9 11-87 89-99
Algorithm
START STEP 1-> Take an array with elements, bool flag[MAX] to Fale, int i, j, n to size of array Step 2-> Loop For from I to 0 and i<n and i++ IF array[i] < 100 && array[i]>=0 Set flag[array[i]]=true End IF Step 3 -> End For Loop Step 4 -> Loop For from i to 0 and i<MAX and ++i IF flag[i] == false Set j=i+1 Loop While j<MAX && flag[j] == false Set j++ End While If j=i+1 Print i End IF Else Print i and j-1 End Else Set i=j End IF Step 5 -> End For Loop STOP
Example
#include <stdio.h> #define MAX 100 int main(int argc, char const *argv[]) { int array[] = {88, 105, 3, 2, 200, 0, 10}; bool flag[MAX] = { false }; //Initializing all the values of flag as false int i, j, n; n = sizeof(array)/sizeof(array[0]); for (i = 0; i < n; i++) { if (array[i] < 100 && array[i]>=0) { flag[array[i]] = true; //Making the value of the elements present in an array as true, So missing will remain false } } for (i = 0; i < MAX; ++i) { if(flag[i] == false) { //Checking for false values j = i+1; //Giving the value of the next iteration while(j<MAX && flag[j] == false) //Checking the value of flag[j] is false j++; if (j==i+1) //For printing the missing number printf("%d
", i); else //For printing the missing range printf("%d-%d
", i, j-1); i = j; //Initializing the range's last value to start from that number } } return 0; }
Output
If we run the above program then it will generate the following output
1 4-9 11-87 89-99
- Related Articles
- Find missing elements of a range in C++
- Count BST subtrees that lie in given range in C++
- Count BST nodes that lie in a given range in C++
- Algorithm to sum ranges that lie within another separate range in JavaScript
- How to print array elements within a given range using Numpy?
- How to find the percentage of values that lie within a range in R data frame column?
- Find pairs with given sum such that pair elements lie in different BSTs in Python
- How to find the percentage of values that lie within a range in a single column R matrix?
- How many fractions lie between 0 and 1?
- Find the one missing number in range using C++
- How to find the percentage of values that lie within a range in column of a data.table object in R?
- Find missing numbers in a sorted list range in Python
- Find missing elements in List in Python
- Python Program that print elements common at specified index of list elements
- Write a program in Python to print the elements in a series between a specific range

Advertisements