fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void plotCirclePoints(int xc, int yc, int x, int y) {
  5. printf("(%d, %d)\n", xc + x, yc + y);
  6. printf("(%d, %d)\n", xc - x, yc + y);
  7. printf("(%d, %d)\n", xc + x, yc - y);
  8. printf("(%d, %d)\n", xc - x, yc - y);
  9. printf("(%d, %d)\n", xc + y, yc + x);
  10. printf("(%d, %d)\n", xc - y, yc + x);
  11. printf("(%d, %d)\n", xc + y, yc - x);
  12. printf("(%d, %d)\n", xc - y, yc - x);
  13. }
  14.  
  15. void midpointCircle(int xc, int yc, int r) {
  16. int x = 0, y = r;
  17. int p = 1 - r;
  18. plotCirclePoints(xc, yc, x, y);
  19. while (x < y) {
  20. x++;
  21. if (p < 0) {
  22. p += 2 * x + 1;
  23. } else {
  24. y--;
  25. p += 2 * x - 2 * y + 1;
  26. }
  27. plotCirclePoints(xc, yc, x, y);
  28. }
  29. }
  30.  
  31. int main() {
  32. int xc, yc, r;
  33. printf("Enter center of the circle (xc, yc): ");
  34. scanf("%d %d", &xc, &yc);
  35. printf("Enter radius of the circle: ");
  36. scanf("%d", &r);
  37. midpointCircle(xc, yc, r);
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5272KB
stdin
0
0
5
stdout
Enter center of the circle (xc, yc): Enter radius of the circle: (0, 5)
(0, 5)
(0, -5)
(0, -5)
(5, 0)
(-5, 0)
(5, 0)
(-5, 0)
(1, 5)
(-1, 5)
(1, -5)
(-1, -5)
(5, 1)
(-5, 1)
(5, -1)
(-5, -1)
(2, 5)
(-2, 5)
(2, -5)
(-2, -5)
(5, 2)
(-5, 2)
(5, -2)
(-5, -2)
(3, 4)
(-3, 4)
(3, -4)
(-3, -4)
(4, 3)
(-4, 3)
(4, -3)
(-4, -3)
(4, 3)
(-4, 3)
(4, -3)
(-4, -3)
(3, 4)
(-3, 4)
(3, -4)
(-3, -4)