Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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=0 Set flag[array[i]]=true End IF Step 3 -> End For Loop Step 4 -> Loop For from i to 0 and i End For Loop STOP
Example
#include#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 =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 ", 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
Advertisements
