-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathElement_check.c
More file actions
43 lines (34 loc) · 767 Bytes
/
Element_check.c
File metadata and controls
43 lines (34 loc) · 767 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
42
43
// To check a if an element is present in the array or not if yes then how many times......
#include <stdio.h>
int main()
{
int x;
printf("Enter size of array: ");
scanf("%d", &x);
int arr[x];
printf("Enter elements : ");
for (int i = 0; i < x; i++)
{
scanf("%d", &arr[i]);
}
int y;
printf("occurance number: "); // desired element you want to check
scanf("%d", &y);
int occur = 0;
for (int i = 0; i < x; i++)
{
if (arr[i] == y)
{
occur++; // To get how many times its occuring
}
}
if (occur)
{
printf("The number %d occur %d times", y, occur);
}
else
{
printf("The number %d does not occur", y);
}
return 0;
}