#include <iostream>
using namespace std;
int main()
{
int size;
cout << "Enter How Many Elements You Want To Insert in Array : ";
cin >> size;
int arr[size];
int c, searchelement;
int flag = 0;
{
int size;
cout << "Enter How Many Elements You Want To Insert in Array : ";
cin >> size;
int arr[size];
int c, searchelement;
int flag = 0;
cout << "\nEnter array element : \n";
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
cout << "Enter the number to search : ";
cin >> searchelement;
cin >> searchelement;
for (c = 0; c < size; c++)
{
if (arr[c] == searchelement)
{
cout << "Element is present at location : " << c + 1;
flag = 1;
break;
}
}
if (!flag)
cout << "Element is not present in array.\n";
{
if (arr[c] == searchelement)
{
cout << "Element is present at location : " << c + 1;
flag = 1;
break;
}
}
if (!flag)
cout << "Element is not present in array.\n";
return 0;
}
}
Output :
Enter How Many Elements You Want To Insert in Array : 6 Enter array element : 1 2 3 4 5 6 Enter the number to search : 3 Element is present at location : 3
0 Comments