# The number of times the needle is overlapped in every second when the C/C ++ code is used

Source: Internet
Author: User

[Liuzy @ linux237 testcode] \$ VI testhms. c

1 # include <stdio. h>
2 # include <stdlib. h>
3 # define hdg 30 // every 30 degrees of rotation in the hour hand
4 # define MDG 6 // The split needle is rotated for 6 degrees each time
5 # define SDG 6 // The second hand rotates for 6 degrees
6 int gethourdg (int h, int m)
7 {
8 int result = H * 30 + M * 0.5; // the minute hand turns 0.5 degrees 30/60 every time it is rotated.
9 return result;
10}
11
12 INT getminutedg (int m, int S)
13 {
14 return M * 6 + S * 0.5; // The second needle is rotated to 0.5 30/60 for each minute
15}
16
17 int getsecdg (int s)
18 {
19 Return S * 6;
20}
21
22 int main ()
23 {
24 For (INT I = 0; I <= 12; I ++)
25 {
26 For (Int J = 0; j <= 59; j ++)
27 {
28 For (int K = 0; k <= 59; k ++)
29 {
30 if (I> 12) I = i-12;
31 int hourdg = gethourdg (I, j) % 360;
32 int minutedg = getminutedg (j, k) % 360;
33 int secdg = getsecdg (k) % 360;
34 if (hourdg = minutedg) & (minutedg = secdg ))
35 {
36 printf ("hour = % d minute = % d Second = % d/N", I, j, k );
37}
38}
39}
40}
41
42}
~

[Liuzy @ linux237 testcode] \$ g ++ testhms. c
Testhms. C: In function 'int gethourdg (INT, INT )':
Testhms. C: 8: Warning: Converting to 'int' from 'double'
Testhms. C: In function 'int getminutedg (INT, INT )':
Testhms. C: 14: Warning: Converting to 'int' from 'double'
[Liuzy @ linux237 testcode] \$ A. Out
Hour = 0 minute = 0 second = 0
Hour = 12 minute = 0 second = 0
[Liuzy @ linux237 testcode] \$

We can see from the result that the coincidence is two times, 0 points and 12 points respectively.

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.