1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include<iostream>
using namespace std;
int main()
{
//int num;
//int ar[17]={7,3,32,2,55,34,6,13,29,22,11,9,1,5,42,39,8};
const int ARRAY_SIZE = 17 ;
const int ar[ARRAY_SIZE] = {7,3,32,2,55,34,6,13,29,22,11,9,1,5,42,39,8};
//cout<<"List = 7,3,32,2,55,34,6,13,29,22,11,9,1,5,42,39,8 "<<endl;
for( int i = 0 ; i < ARRAY_SIZE ; ++i ) std::cout << ar[i] << ' ' ;
std::cout << '\n' ;
cout<<"Enter an integer in the list to search for: ";
int num ; cin >> num ;
//for(int i=0; i<(ar[17]-1); ++i)
for( int i = 0 ; i < ARRAY_SIZE ; ++i )
{
if( num == ar[i] )
{
//cout<<"Item found at index ["<<ar[i]<<"]"<<endl;
cout<<"Item found at index [" << i << "]\n" ;
}
}
}
|