position of array in c 2b 2b

Solutions on MaxInterview for position of array in c 2b 2b by the best coders in the world

showing results for - "position of array in c 2b 2b"
Fran
01 Oct 2018
1#include <iostream>
2using namespace std;
3 
4int main()
5{
6    int arr[] = { 6, 3, 5, 2, 8 };
7    int n = sizeof(arr)/sizeof(arr[0]);
8 
9    int elem = 2;
10 
11    int i = 0;
12    while (i < n)
13    {
14        if (arr[i] == elem) {
15            break;
16        }
17        i++;
18    }
19 
20    if (i < n)
21    {
22        cout << "Element " << elem << " is present at index " << i
23             << " in the given array";
24    }
25    else {
26        cout << "Element is not present in the given array";
27    }
28 
29    return 0;
30}