Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

• # Program to print missing elements that lie in range 0 99

• 0
• 0
• 0
• 0
• 0
• 0
• 0
• 0
• 591
Comment on it

The logic of the program is to use a boolean array named presentseen of size 100, the size is defined by macro LIMIT. The boolean array is used to keep track of array elements that lie in range 0 to 99, which is initially initialized to false. An input array passed to printMissing function is traversed and  elements present in passed array are marked in the boolean array as true. Once all elements in passed array are marked as true in boolean array, the boolean array is then used to print missing elements using ternary operator.

``````// C program for print missing elements
#include<stdio.h>
#define LIMIT 100

void printMissing(int arr[], int n)
{
// Initialize all number from 0 to 99 as false
bool presentseen[LIMIT] = {false};

// Mark present elements in range [0-99] as true
for (int i=0; i<n; i++)
if (arr[i] < LIMIT)
presentseen[arr[i]] = true;

// Print missing element
int i = 0;
while (i < LIMIT)
{
// If i is missing
if (presentseen[i] == false)
{
// Find if there are more missing elements after i
int j = i+1;
while (j < LIMIT && presentseen[j] == false)
j++;

// Print missing single or range
(i+1 == j)? printf("%d\n", i): printf("%d-%d\n", i, j-1);

// Update i
i = j;
}
else
i++;
}
}

int main()
{
int arr[] = {88, 105, 3, 2, 200, 0, 10};
int n = sizeof(arr)/sizeof(arr[0]);
printMissing(arr, n);
return 0;
}
``````

Output:

```1
4-9
11-87
89-99```

## 0 Comment(s)

OR
OR
Register

OR
Fill out the form below and instructions to reset your password will be emailed to you:

• Hire
• Post Projects

### Post Projects

• All at 0 Cost ....
• Post Tech Job
• Select Best Bidder
• Track the Project
• Approve Work and Pay safely
• Browse Nerds
• Work
• Find Projects Find Projects
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...
• Manage
• Company Company

### Manage Company

• All at 0 Cost ....
• Manage Company and Employee Profiles
• Company wide Employee Productivity Reports
• Knowledge Sharing and Collaboration Tools
• Get Sales Lead and Bid for Tech Projects
• Send Invoices and Receive Payment Safely
• Learn
• Nerd Digest Nerd Digest
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...
• Tech Q & A Tech Q & A
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
View more...
View less...