-
Notifications
You must be signed in to change notification settings - Fork 1
/
Q-33.c
41 lines (35 loc) · 796 Bytes
/
Q-33.c
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
#include<stdio.h>
void main() {
int size, element, i;
printf("Enter the size of the Array: ");
scanf("%d",&size);
int arr[size], pos[size], posIndex=0;
printf("Enter %d Elements: \n");
for(i=0; i < size; i++) {
scanf("%d", &arr[i]);
}
system("cls");
// Displaying Array
printf("Given Array: ");
for(i=0; i < size; i++) {
printf("%d ",arr[i]);
}
printf("\n\nEnter the element to be searched: ");
scanf("%d",&element);
for(i=0; i < size; i++) {
if(arr[i] == element) {
pos[posIndex++] = i+1;
}
}
if(posIndex != 0) {
printf("%d found at position: ",element);
for(i=0; i<posIndex; i++) {
printf("%d, ",pos[i]);
}
return;
}
else {
printf("%d not found in this Array!",element);
return;
}
}