Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions