C++ program is print the smallest missing element in sorted array

C++ program is printing the smallest missing element in a sorted array. Using this program to the smallest missing element in the array. An array is a collection of elements of the same kind that are stored in contiguous memory locations and may be accessed separately using a unique identifier’s index. Without having to define five individual variables, an array of five int values can be declared.

using namespace std;
int small(int arr[], int start, int end)
if (start > end)
return end + 1;
if (start != arr[start])
return start;
int mid = (start + end) / 2;
if (arr[mid] == mid)
return small(arr, mid + 1, end);
return small(arr, start, mid);
int main()
int arr[100], n, i;
cout << "Enter number of elements";
cin >> n;
cout << "\nEnter elements";
for (i = 0; i < n; i++)
cin >> arr[i];
cout << "Original array";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
int answer;
answer = small(arr, 0, n - 1);
cout << "\nSmallest missing element is " << answer;
return 0;


Enter number of elements3

Enter elements45
Original array45 67 89
Smallest missing element is 0

What is array and how to implement in c++ program

The array is a data structure in C++ that stores a fixed-size sequential collection of objects of the same type in a fixed-size sequential order. Although an array is used to hold data, it is often more beneficial to conceive of it as a collection of variables of the same type. All arrays are made up of memory regions that are connected in some way.

What is return statement in c++ program

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the caller function a value.