-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram58.c
64 lines (50 loc) · 1015 Bytes
/
Program58.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 checks whether the digit is present in input or not
#include<stdio.h>
#include<stdbool.h>
bool CheckDigit(int iNo, int iSearch)
{
int iDigit = 0;
int iCnt = 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)
{
break;
}
iNo = iNo / 10;
}
if(iDigit == iSearch)
{
return true;
}
else{
return false;
}
}
int main()
{
int iValue1 = 0, iValue2 = 0;
bool bRet = false;
printf("Enter number:\n");
scanf("%d",&iValue1);
printf("Enter digit between 0 to 9:\n");
scanf("%d",&iValue2);
bRet = CheckDigit(iValue1,iValue2);
if(bRet == true)
{
printf("%d is present in %d\n",iValue2,iValue1);
}
else{
printf("%d is not present in %d",iValue2, iValue1);
}
}