-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path34.c
More file actions
37 lines (37 loc) · 764 Bytes
/
34.c
File metadata and controls
37 lines (37 loc) · 764 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
#include <stdio.h>
int main()
{
int n, i, element, found = 0;
// Input size of the array
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
int arr[n];
// Input array elements
printf("Enter %d elements:\n", n);
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
// Input element to search
printf("Enter the element to search: ");
scanf("%d", &element);
// Search for the element
for (i = 0; i < n; i++)
{
if (arr[i] == element)
{
found = 1;
break; // stop searching once found
}
}
// Output result
if (found)
{
printf("Element %d found at position %d.\n", element, i + 1);
}
else
{
printf("Element %d not found in the array.\n", element);
}
return 0;
}