{"id":26182,"date":"2017-10-26T20:20:09","date_gmt":"2017-10-26T14:50:09","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=26182"},"modified":"2017-10-26T20:20:09","modified_gmt":"2017-10-26T14:50:09","slug":"c-programming-draw-circle-without-floating-point-arithmetic","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/c-programming-draw-circle-without-floating-point-arithmetic\/","title":{"rendered":"C Programming &#8211; Draw a circle without floating point arithmetic"},"content":{"rendered":"<p>Given a radius of a circle, draw the circle without using floating point arithmetic.<span id=\"more-142261\"><\/span><\/p>\n<p>Following program uses a simple concept. Let the radius of the circle be r. Consider a square of size (2r+1)*(2r+1) around the circle to be drawn. Now walk through every point inside the square. For every every point (x,y), if (x, y) lies inside the circle (or x^2+ y^2 < r^2), then print it, otherwise print space.<\/p>\n[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%0Avoid%20drawCircle(int%20r)%0A%7B%0A%2F%2F%20Consider%20a%20rectangle%20of%20size%20N*N%0Aint%20N%20%3D%202*r%2B1%3B%0A%0Aint%20x%2C%20y%3B%20%2F%2F%20Coordinates%20inside%20the%20rectangle%0A%0A%2F%2F%20Draw%20a%20square%20of%20size%20N*N.%0Afor%20(int%20i%20%3D%200%3B%20i%20%3C%20N%3B%20i%2B%2B)%0A%7B%0Afor%20(int%20j%20%3D%200%3B%20j%20%3C%20N%3B%20j%2B%2B)%0A%7B%0A%2F%2F%20Start%20from%20the%20left%20most%20corner%20point%0Ax%20%3D%20i-r%3B%0Ay%20%3D%20j-r%3B%0A%0A%2F%2F%20If%20this%20point%20is%20inside%20the%20circle%2C%20print%20it%0Aif%20(x*x%20%2B%20y*y%20%3C%3D%20r*r%2B1%20)%0Aprintf(%22.%22)%3B%0Aelse%20%2F%2F%20If%20outside%20the%20circle%2C%20print%20space%0Aprintf(%22%20%22)%3B%0Aprintf(%22%20%22)%3B%0A%7D%0Aprintf(%22%5Cn%22)%3B%0A%7D%0A%7D%0A%0A%2F%2F%20Driver%20Program%20to%20test%20above%20function%0Aint%20main()%0A%7B%0AdrawCircle(8)%3B%0Areturn%200%3B%0A%7D\u201d message=\u201dC Program\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><strong>Output:<\/strong><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-26188\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/05\/circle.png\" alt=\"Circle\" width=\"300\" height=\"178\" \/><br \/>\n[ad type=\u201dbanner\u201d]\n","protected":false},"excerpt":{"rendered":"<p>C Programming Draw a circle without floating point arithmetic &#8211; Mathematical Algorithms &#8211; Following program uses a simple concept Let the radius  be r. <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69969,69866,1,74058],"tags":[70860,70814,69930,70812,70842,77626,70843,70815,73138,73135,73144,77630,70972,77623,75517,70857,75062,75067,71983,73134,77628,77631,77627,73158,77624,74066,70855,75068,74832,76933,74069,73145,70970,75430,70810,70836,75694,71159,73146,72834,76930,73148,73150,77303,70826,77625,73147,77629,75960,73140],"class_list":["post-26182","post","type-post","status-publish","format-standard","hentry","category-algorithm","category-c-programming","category-coding","category-mathematical-algorithms","tag-array-definition-in-c","tag-array-in-c","tag-array-in-c-language","tag-array-in-c-programming","tag-array-in-c-programming-examples","tag-array-in-cpp","tag-array-programming","tag-array-programs-in-c","tag-array-programs-in-c-with-output","tag-ascending-order-program-in-c","tag-c-array-programs","tag-c-program-for-addition","tag-c-program-for-selection-sort","tag-c-program-for-sorting","tag-c-program-for-student-details-using-structure","tag-c-program-to-add-two-numbers","tag-c-program-to-count-number-of-words-in-a-string","tag-c-program-to-print-given-number-in-words","tag-c-program-to-separate-digits-of-a-number","tag-c-program-to-store-student-information-using-array","tag-c-programming-error-finding-questions-with-answers","tag-c-programming-exercises","tag-c-programming-output-questions-and-answers","tag-c-string-functions","tag-data-structures-in-c-programs-with-output","tag-for-loop-c-programming","tag-for-loop-in-c-programming-example","tag-function-program-in-c","tag-functions-in-c-programming-with-examples","tag-how-to-input-a-string-in-c","tag-if-c-programming","tag-list-of-array-programs-in-c","tag-selection-sort-program-in-c","tag-simple-addition-program-in-c","tag-simple-c-programs","tag-simple-c-programs-with-output","tag-sorting-c-program","tag-sorting-program","tag-sorting-program-in-c","tag-string-array-in-c","tag-string-functions-in-c","tag-string-programs-in-c","tag-two-dimensional-array-in-c-example","tag-types-of-array-in-c","tag-wap-in-c","tag-what-will-be-the-output-of-the-program","tag-write-a-complete-program-that-declares-an-integer-variable","tag-write-ac-program-to-implement-singly-linked-list-with-output","tag-write-ac-program-to-print-the-following-pattern","tag-write-ac-program-to-search-an-element-in-an-array"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/26182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=26182"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/26182\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=26182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=26182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=26182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}