Given a radius of a circle, draw the circle without using floating point arithmetic.
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.
# Python3 code to demonstrate to draw
# circle without floating
# point arithmetic
# Consider a rectangle of size N*N
N = 2 * r + 1
# Draw a square of size N*N.
for i in range(N):
for j in range(N):
# Start from the left most corner point
x = i – r
y = j – r
# If this point is inside the circle,
# print it
if x * x + y * y <= r * r + 1: print(".", end = " ") # If outside the circle, print space else: print(" ", end = " ") print() # Driver Code if __name__ == "__main__": drawCircle(8) # This code is contributed # by vibhu4agarwal [tabby title="C#"]
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- sizeof() for Floating Constant in C
- Why learning C Programming is a must?
- Step by Step guide to Write your own WordPress Template
- Structured Programming Approach with Advantages and Disadvantages
- Print all subsequences of a string using ArrayList
- A subtle guide to get that college internship
- Sudo Placement 2 | Course Structure
- How to prepare for AMCAT?
- How to attempt Function Coding Questions?
- Editors and Its types in System Programming
- File globbing in Linux
- Functional Dependency and Attribute Closure
- GATE CS 2016 Syllabus
- MAQ Software most Frequently Asked Questions