fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int xc = 20;
  6. int yc = 15;
  7. int r = 10;
  8.  
  9. void plot(int x, int y)
  10. {
  11. cout << "(" << x << ", " << y << ") ";
  12. }
  13.  
  14. void midpointCircle()
  15. {
  16. int x = 0;
  17. int y = r;
  18. int p = 1 - r;
  19.  
  20. while (x <= y)
  21. {
  22. plot(xc + x, yc + y);
  23. plot(xc - x, yc + y);
  24. plot(xc + x, yc - y);
  25. plot(xc - x, yc - y);
  26.  
  27. plot(xc + y, yc + x);
  28. plot(xc - y, yc + x);
  29. plot(xc + y, yc - x);
  30. plot(xc - y, yc - x);
  31.  
  32. cout << endl;
  33.  
  34. if (p < 0)
  35. {
  36. p = p + 2 * x + 3;
  37. }
  38. else
  39. {
  40. p = p + 2 * (x - y) + 5;
  41. y--;
  42. }
  43.  
  44. x++;
  45. }
  46. }
  47.  
  48. int main()
  49. {
  50. cout << "Midpoint Circle Drawing Algorithm\n";
  51. cout << "Center = (" << xc << ", " << yc << ")\n";
  52. cout << "Radius = " << r << "\n\n";
  53.  
  54. midpointCircle();
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Midpoint Circle Drawing Algorithm
Center = (20, 15)
Radius = 10

(20, 25) (20, 25) (20, 5) (20, 5) (30, 15) (10, 15) (30, 15) (10, 15) 
(21, 25) (19, 25) (21, 5) (19, 5) (30, 16) (10, 16) (30, 14) (10, 14) 
(22, 25) (18, 25) (22, 5) (18, 5) (30, 17) (10, 17) (30, 13) (10, 13) 
(23, 25) (17, 25) (23, 5) (17, 5) (30, 18) (10, 18) (30, 12) (10, 12) 
(24, 24) (16, 24) (24, 6) (16, 6) (29, 19) (11, 19) (29, 11) (11, 11) 
(25, 24) (15, 24) (25, 6) (15, 6) (29, 20) (11, 20) (29, 10) (11, 10) 
(26, 23) (14, 23) (26, 7) (14, 7) (28, 21) (12, 21) (28, 9) (12, 9) 
(27, 22) (13, 22) (27, 8) (13, 8) (27, 22) (13, 22) (27, 8) (13, 8)