VOOZH about

URL: https://www.geeksforgeeks.org/dsa/draw-circle-without-floating-point-arithmetic/

⇱ Draw a circle without floating point arithmetic - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Draw a circle without floating point arithmetic

Last Updated : 21 Jun, 2022

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  point (x,y), if (x, y) lies inside the circle (or  x2+ y2 < r2), then print it, otherwise print space.
 

Approach: 

1. draw the rectangle

2. check if the point lie inside or on the circle using formula  x2+ y2 < r2.

3. If it fulfill the condition print the star else print blank space

Algorithm: 

Step 1: Take the input of radius

Step 2: Calculate the size of rectangle

Step 3: Draw the rectangle using the nested for loop

Step 4: Start coordinates from left most corner

Step 5: Check if the coordinates lie inside the circle, if yes Print the star else print blank space.

Output: 
 

👁 Image

Time Complexity: O(N2)

Space Complexity: O(N2)
 

Comment
Article Tags:
Article Tags: