-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQ-33.cpp
43 lines (36 loc) · 864 Bytes
/
Q-33.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
using namespace std;
int main() {
int size, element;
cout<< "Enter the size of the Array: ";
cin>> size;
int arr[size] , pos[size] , posIndex=0;
cout<< "Enter "<< size << " Elements: "<< endl;
for(int i=0; i < size; i++) {
cin>> arr[i];
}
system("cls");
//Displaying Array
cout<< "Given Array: ";
for(int i=0; i < size; i++) {
cout<< arr[i]<< " ";
}
cout<< "\n\nEnter the element to be searched: ";
cin>> element;
for(int i=0; i < size; i++) {
if(arr[i] == element) {
pos[posIndex++] = i+1;
}
}
if(posIndex != 0) {
cout<< element<< " found at position: ";
for(int i=0; i<posIndex; i++) {
cout<< pos[i]<< ", ";
}
return 1;
}
else {
cout<< element<< " not found in this Array!"<< endl;
return 0;
}
}