Coders Packet

Positive Missing Number From Unsorted Array In C++

By Aditi Mishra

  • .vscode/
  • MissingNumber.exe
  • MissingNumber.cpp
  • a.exe
  • This project resolves the problem of positive missing numbers from unsorted arrays in C++ language . We can search any numbers entered by the user from the array if it is present.

    Searching Positive Missing Numbers from unsorted arrays is the main task of my program which is done in C++ language.

    An array "a" is there with size "n" is taken, then first sorting is done and after that, for searching the element, logic has been applied in the program.



    using namespace std;
        int missingNumber(int arr[], int n) { 
        sort(arr, arr+n);
        int i,k=0;
        for(i=0; i<n; i++)
        int max1=1;
        for(k=i; k<n; k++)
                    return max1;
                if(arr[k] == arr[k-1])
                max1= max1+1;    
          return (max1);
    int main(){
        int t;
        cout<<"\nEnter the number of testcases:-> ";
            int n;
            cout<<"\nEnter the size of array:-> ";
        int a[n];
        cout<<"\nEnter the elements of array:-> ";
        for(int i=0;i<n;i++){
        cout<<"\nMissing number is:-> ";
    return 0;

    Input- Enter the number of testcases:-> 2

              Enter the size of array:-> 5

              Enter the elements of array:-> 1 2 3 4 5

    Output- Missing number is:-> 6


    Input- Enter the size of array:-> 7

              Enter the elements of array:-> 4 5 8 2 -5 0 6

    Output- Missing number is:-> 1

    Download Complete Code


    No comments yet