-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray 3.c
More file actions
41 lines (33 loc) · 732 Bytes
/
Copy patharray 3.c
File metadata and controls
41 lines (33 loc) · 732 Bytes
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>
int main()
{
int n, i, key;
int found = 0;
// Input the number of elements in the array printf("Enter the number of elements in the array: ");
scanf("%d", &n);
int arr[n];
printf("Enter the elements of the array:\n");
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
printf("Enter the element to be searched: ");
scanf("%d", &key);
for (i = 0; i < n; i++)
{
if (arr[i] == key)
{
found = 1;
break;
}
}
if (found)
{
printf("Element %d found at position %d.\n", key, i + 1);
}
else
{
printf("Element %d not found in the array.\n", key);
}
return 0;
}