Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to search in array c++

// C++ Program to search any element or number in an array
 
#include <iostream>
using namespace std;
   
int main(){
    int input[100], count, i, num;
       
    cout << "Enter Number of Elements in Array
";
    cin >> count;
     
    cout << "Enter " << count << " numbers 
";
      
    // Read array elements
    for(i = 0; i < count; i++){
        cin >> input[i];
    }
      
    cout << "Enter a number to serach in Array
";
    cin >> num;
      
    // search num in inputArray from index 0 to elementCount-1 
    for(i = 0; i < count; i++){
        if(input[i] == num){
            cout << "Element found at index " << i;
            break;
        }
    }
      
    if(i == count){
        cout  << "Element Not Present in Input Array
";
    }
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: ascii conversion cpp 
Cpp :: power of two c++ 
Cpp :: min heap priority queue c++ 
Cpp :: c++ min int 
Cpp :: pointer in return function c++ 
Cpp :: number of digits in int c++ 
Cpp :: string split by space c++ 
Cpp :: getline(cin string) not working 
Cpp :: array to string c++ 
Cpp :: #define online judge in cpp 
Cpp :: c++ 14 for sublime windoes build system 
Cpp :: how to compare two char* in c++ 
Cpp :: what is g++ and gcc 
Cpp :: max two numbers c++ 
Cpp :: macros in c++ 
Cpp :: login system with c++ 
Cpp :: How do I read computer current time in c++ 
Cpp :: input full line as input in cpp 
Cpp :: how to concatenate two vectors in c++ 
Cpp :: check even or odd c++ 
Cpp :: C++ Integer Input/Output 
Cpp :: char to int in c++ 
Cpp :: exception handling class c++ 
Cpp :: toString method in c++ using sstream 
Cpp :: long long int range c++ 
Cpp :: constrain function in arduino 
Cpp :: c++ recorrer string 
Cpp :: struct node 
Cpp :: lists occurrences of characters in the string c++ 
Cpp :: c++ generic pointer 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =