Question: #include #include #include using namespace std; vector missing ( const vector& arr, int N ) { vector missing _ numbers; vector present ( N +

#include
#include
#include
using namespace std;
vector missing(const vector& arr, int N){
vector missing_numbers;
vector present(N +1, false); // Initialize a boolean vector to mark presence of numbers
// Mark numbers as present
for (int num : arr){
present[num]= true;
}
// Find missing numbers
for (int i =1; i <= N; ++i){
if (!present[i]){
missing_numbers.push_back(i);
}
}
return missing_numbers;
}
int main(){
int N;
cout << "Enter the value of N: ";
cin >> N;
cout << "Enter a series of integers from 1 to N (separated by spaces): ";
vector arr(N);
for (int i =0; i < N; ++i){
cin >> arr[i];
}
vector missing_numbers = missing(arr, N);
if (missing_numbers.empty()){
cout <<"No numbers are missing." << endl;
}
else {
cout << "The missing numbers are: ";
for (int num : missing_numbers){
cout << num <<"";
}
cout << endl;
}
return 0;
}
Help have an output like this :
Enter the value of N: 10
Enter a series of integers from 1 to N (separated by spaces): 135710
The missing numbers are: 24689

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!