-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror-checksum.c
87 lines (51 loc) · 1.28 KB
/
error-checksum.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*Error Detection mechanism are widely employed in industry to identify the error in data communication. You have to have design a simple error detection mechanism, which uses parity digit. A parity digit is appended to the decimal representation of the number to make the total number of 9's even.
Given an integers A . Your task is identify the parity bit.
Constraint:
The integer A is always positive
Refrain from using floating point variables for storing A.
Input:
The input will consist of a number.
Output:
The program should print:
YES, if the parity digit is required to make the total number of digit 9's even.
NO, if parity digit is not required
The output should be followed by a newline.
Sample TestCase:
TestCase1:
Input
919
Output:
NO
TestCase2:
Input
94
Output:
YES
Explanation:
TEST CASE1: The number of 9's is 919 is even. Parity digit is not required.
TEST CASE2: The number of 9's is 94 is odd. Parity digit is required.*/
// solution:
#include <stdio.h>
int main()
{
int A;
int count = 0;
scanf("%d", &A);
while (A != 0)
{
if (A % 10 == 9)
{
count++;
}
A = A / 10;
}
if (count % 2 == 0)
{
printf("NO");
}
else
{
printf("YES");
}
return 0;
}