-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program59.c
64 lines (46 loc) · 952 Bytes
/
Program59.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//write a program which accepts a number and a digit from user and return the frequency of digit
#include<stdio.h>
#include<stdbool.h>
int CheckFrequency(int iNo, int iSearch)
{
int iDigit = 0;
int iCount = 0;
if((iSearch < 0) || (iSearch > 9)) //filter
{
printf("Enter the digit in range 0 to 9\n");
return false;
}
if(iNo < 0) //updater
{
iNo = -iNo;
}
while(iNo != 0)
{
iDigit = iNo % 10;
if(iDigit == iSearch)
{
iCount++;
}
iNo = iNo / 10;
}
return iCount;
if(iDigit == iSearch)
{
return true;
}
else{
return false;
}
}
int main()
{
int iValue1 = 0, iValue2 = 0;
int iRet = false;
printf("Enter number:\n");
scanf("%d",&iValue1);
printf("Enter digit between 0 to 9:\n");
scanf("%d",&iValue2);
iRet = CheckFrequency(iValue1,iValue2);
printf("Frequency of %d in %d is : %d ",iValue2,iValue1,iRet);
return 0;
}