Write a program to search the array element. Enter a value from the keyboard and find out the location of the entered value in the array. If the entered number is not found in the array display the message
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
  std::vector<int> v { 1, 5, 8, 3, 2, 10, -10, -5, 4, -4};
  int value;
  std::cin >> value;
  if (auto it = std::find(v.begin(), v.end(), value);
    it != v.end())
  {
    std::cout << "location: " << it - v.begin() << '\n';
  }
  else {
    std::cout << "couldn't found the value\n";
  }
  return 0;
}
Comments
Leave a comment