Code :
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int array[20], elements, elem_search, each_elements, i, flag = 0;
cout<<"How many elements? : ";
cin>>elements;
cout<<"Enter elements list in the array: ";
for (i=0; i<elements; i++)
cin>>array[i];
cout<<"Enter elements you want to search : ";
cin>>elem_search;
for (i=0; i<elements; i++) {
if (array[i] == elem_search) {
flag = 1;
break;
}
}
if (flag == 0) {
cout<<"Not Found";
}
else {
cout<<"Found";
}
}
Output :
How many elements? : 4
Enter elements list in the array:
4
2
7
5
Enter elements you want to search : 7
Found
IDE Used To Test This Code : DEV C++
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int array[20], elements, elem_search, each_elements, i, flag = 0;
cout<<"How many elements? : ";
cin>>elements;
cout<<"Enter elements list in the array: ";
for (i=0; i<elements; i++)
cin>>array[i];
cout<<"Enter elements you want to search : ";
cin>>elem_search;
for (i=0; i<elements; i++) {
if (array[i] == elem_search) {
flag = 1;
break;
}
}
if (flag == 0) {
cout<<"Not Found";
}
else {
cout<<"Found";
}
}
Output :
How many elements? : 4
Enter elements list in the array:
4
2
7
5
Enter elements you want to search : 7
Found
IDE Used To Test This Code : DEV C++
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.
Post a Comment