Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <locale.h>
  5. #include <windows.h>
  6.  
  7. struct Box {
  8. int x, y, a;
  9. };
  10.  
  11. void inputDataForBox(struct Box* boxs, int N) {
  12. for (int i = 0; i < N; i++) {
  13. printf("Введите для %d квадрата координаты центра (x,y) и его длину: ", i+1);
  14. do {
  15. scanf_s("%d %d %d", &boxs[i].x, &boxs[i].y, &boxs[i].a);
  16. if (boxs[i].a <= 0) printf("Длина квадрата не может быть неположительной.\n");
  17. } while (boxs[i].a <= 0);
  18. }
  19. }
  20.  
  21. void printDataBox(struct Box* boxs, int N) {
  22. for (int i = 0; i < N; i++)
  23. printf("Квадрат N%d: координаты центра (%d, %d), длина стороны %d\n", i+1, boxs[i].x, boxs[i].y, boxs[i].a);
  24. }
  25.  
  26. int boxContentThePoint(struct Box box, int px, int py) {
  27. if ((box.x - box.a <= px) && (box.x + box.a >= px) && (box.y + box.a >= py) && (box.y - box.a <= py)) return 1;
  28. else return 0;
  29. }
  30.  
  31. int square(struct Box box) {
  32. return pow(box.a, 2);
  33. }
  34.  
  35. void main() {
  36. setlocale(LC_ALL, "rus");
  37.  
  38. struct Box* boxs;
  39. int N;
  40.  
  41. printf("Введите количество квадратов: ");
  42. scanf_s("%d", &N);
  43.  
  44. boxs = (struct Box*)malloc(N * sizeof(struct Box));
  45.  
  46. inputDataForBox(boxs, N);
  47. printDataBox(boxs, N);
  48.  
  49. //printf("%d", boxContentThePoint(boxs[0], 3, 3));
  50.  
  51. getchar();
  52. getchar();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement