-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_array.cpp
More file actions
36 lines (28 loc) · 1.24 KB
/
function_array.cpp
File metadata and controls
36 lines (28 loc) · 1.24 KB
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
// cpp program function reciving argumnets as array , array size and the constant k which is to be returned by the code as
// the frequency of the digit in the all of array elements
// driver code is not written here
// the working num() function which returns the number
int num(int a[], int n, int k)
{
int counter = 0 ; // to store the number of times the value is repeated
for(int i=0; i<=n-1;i++)
{
if(a[i]==k)
{
counter++ ;
}
else
{
// loop to check the frequency of the constant k in the elements of the array being 1,2,3...etc digits ..
while(a[i]!=0)
{
int rem ;
rem=a[i]%10;
if(rem==k)
counter++;
a[i]=a[i]/10;
}
}
}
return counter ;
}