r how many number of iteration searched value is found

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.1: One-dimensional Arrays
Problem 10E: (Electrical eng.) Write a program that specifies three one-dimensional arrays named current,...
icon
Related questions
Question

#include <iostream>

using namespace std;

int main()
{
    int a[100],n,i,item,loc=0;
    cout<<"Enter number of elements: ";
    cin>>n;
    cout<<"\nEnter numbers:\n";
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    cout<<"\nEnter number to search:";
    cin>>item;
    for(i=1;i<=n;i++)
    {
        if(item==a[i])
        {
            loc=i;
            break;
        }
    }
    if(loc>0)
    {
        cout<<loc<<" is the location of item";
    }
    else
    cout<<"\nno. not found";
}

Q: edit the code that shows after how many number of iteration searched value is found

Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr