fork download
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <assert.h>
  6. #include <limits.h>
  7. #include <stdbool.h>
  8.  
  9. typedef struct point {
  10. int x;
  11. int y;
  12. } point;
  13.  
  14. float distance(point p, point q) {
  15. return sqrt((p.x - q.x)*(p.x - q.x) + (p.y - q.y)*(p.y - q.y));
  16. }
  17.  
  18. int withinCircle(point circleCentre, point p, int radius) {
  19. float dist = distance(circleCentre, p);
  20. if (!(dist > (float) radius)) {
  21. return 1;
  22. } else {
  23. return 0;
  24. }
  25. }
  26.  
  27. int main(void){
  28. point pixel;
  29. int w, h;
  30. scanf("%d %d",&w,&h);
  31. char *canvas = malloc(w * h);
  32.  
  33. int circleX, circleY;
  34. int r;
  35. scanf("%d %d %d",&circleX,&circleY,&r);
  36. point circleCentre;
  37. circleCentre.x = circleX; circleCentre.y = circleY;
  38.  
  39. for (int i = 0; i < h; i++) {
  40. for (int j = 0; j < w; j++) {
  41. pixel.x = j; pixel.y = i;
  42. if (withinCircle(circleCentre, pixel, r)) {
  43. *(canvas + i*w + j) = '#';
  44. } else {
  45. *(canvas + i*w + j) = '.';
  46. }
  47. }
  48. }
  49.  
  50. for (int i = 0; i < h; i++) {
  51. for (int j = 0; j < w; j++) {
  52. printf("%c", *(canvas + i*w + j));
  53. }
  54. printf("\n");
  55. }
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0s 9432KB
stdin
20 16
9 6 5
stdout
....................
.........#..........
......#######.......
.....#########......
.....#########......
.....#########......
....###########.....
.....#########......
.....#########......
.....#########......
......#######.......
.........#..........
....................
....................
....................
....................