The program can be assembly embedded in C++, Have the user supply the data throu
ID: 3536902 • Letter: T
Question
The program can be assembly embedded in C++, Have the user supply the data through C++ for length of array , and allow them to populate it in C++. Once the array is full complete the rest in assembly.
Also needs to ask them for S.
Needs to be simple, not complex.
So that a beginner will understand everything written.
Suppose we are given a sorted array of integers. Further assume that the array is sorted
in ascending order. Then we can modify the linear search procedure to search for a
number S so that it stops searching either when S is found or when a number greater
than S is found. For this exercise, assume that the user supplies the input data in sorted
order.
Explanation / Answer
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int i,j,n,a[100];
cout<<"enter the size of array"<<endl;
cin>>n;
cout<<"enter the numbers in ascending order"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"enter the element you want to search"<<endl;
cin>>j;
for(i=0;i<n;i++)
{
if(j==a[i])
{
cout<<"same element found"<<endl;
break;
}
else if(j>a[i]){
cout<<"greater element found"<<endl;
break;
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.