Computer Science, asked by preet1999, 1 year ago


(i) Write a function that takes an integer array and an integer variable as an argument. The function then finds the position of the element in the array using binary search algorithm. Assume that the array is sorted in ascending order.

Answers

Answered by wajahatkincsem
3

#include <iostream>

using namespace std;

 

const int N=10;

 

int main()

{

    int t[N],i,j,V;

    bool found;

    for(i=0;i<N;i++)

    {

        cout << "Type an integer: ";

        cin >> t[i];

    }

    cout << "Type the value of V: ";

    cin >> V;

 

    for (i=0;i<N;i++)

        if (t[i]==V)

        {

            for (j=i;j<N-1;j++)

                t[j]=t[j+1];

            t[N-1]=0;

            break;

        }

 

    for(i=0;i<N;i++)

        cout << t[i] << endl;

 

    return 0;

}

Similar questions