{"id":7796,"date":"2026-10-01T00:01:08","date_gmt":"2026-10-01T07:01:08","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7796"},"modified":"2026-09-26T17:02:59","modified_gmt":"2026-09-27T00:02:59","slug":"the-clock-angle-problem","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7796","title":{"rendered":"The Clock Angle Problem"},"content":{"rendered":"<p>Reading an analog clock is a skill that some kids need to master these days. Oh, I&#8217;m sure that eventually everyone figures it out. When I was a kid, digital clocks were rare. No, we all learned how to tell time by looking at a round disk with 12 numbers and a big hand and a little hand. If a second hand was available, well it was just more entertainment for the terminally bored child.<br \/>\n<!--more--><br \/>\nBefore getting into this month&#8217;s challenge, which is the big hand and which is the little hand? Is the little hand the short, squat one? Or is the little hand the one that tells minutes? I can see how some young people may be confused. Whatever.<\/p>\n<p>Figure 1 illustrates an analog clock showing 3:00, PM or AM. The minute hand (the long one) is pointed straight up at 12. The hour hand (the short one) is pointed at the 3. The angular difference between these two hands is 90&deg;. It&#8217;s also 270&deg; if you go around the long way, but I prefer 90&deg;.<\/p>\n<div id=\"attachment_7798\" style=\"width: 454px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-7798\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/10\/10exercise-figure1.png\" alt=\"\" width=\"444\" height=\"443\" class=\"size-full wp-image-7798\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/10\/10exercise-figure1.png 444w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/10\/10exercise-figure1-300x300.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/10\/10exercise-figure1-150x150.png 150w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2026\/10\/10exercise-figure1-301x300.png 301w\" sizes=\"auto, (max-width: 444px) 100vw, 444px\" \/><p id=\"caption-attachment-7798\" class=\"wp-caption-text\">Figure 1. It&#8217;s three o&#8217;clock.<\/p><\/div>\n<p>Your task for this month&#8217;s C programming exercise is to code a program that calculates the angle between the two clock hands. Accept valid input for hours and minutes. Then determine the angle between the hands on an analog clock, like the one shown in Figure 1.<\/p>\n<p>I have some rules.<\/p>\n<p>First, ensure that the angle is always positive. While you can say that the angle in Figure 1 is -90&deg;, your program should report it as positive 90&deg;.<\/p>\n<p>Second, always report the smallest angle. For example, in Figure 1 the result is 90&deg; and not 270&deg; (or -270&deg;).<\/p>\n<p>Here is a sample run from my solution:<\/p>\n<pre>Enter the hour: 3\r\nEnter the minute: 0\r\nThe angle for 3:00 is 90 degrees<\/pre>\n<p>This problem may not make sense if you&#8217;re too young to remember analog clocks, but age is not an excuse. The goal is to use your C programming skills to code the clock angle problem. Many solutions are possible with this puzzle. I&#8217;ll post mine in a week.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How many degrees are there between the big hand and the little hand? <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7796\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-7796","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7796"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7796\/revisions"}],"predecessor-version":[{"id":7815,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7796\/revisions\/7815"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}