Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #define MAXN 5
  5.  
  6. int main (){
  7. printf ("Inserire il numero di punti\n");
  8. int n;
  9. char buffer[1024];
  10. fgets (buffer, sizeof(buffer), stdin);
  11. n=atoi(buffer);
  12. if (n>MAXN){
  13. printf ("Limite massimo superato\n");
  14. n=MAXN;
  15. }
  16. struct coord{
  17. float x;
  18. float y;
  19. };
  20. struct coord points[n];
  21. printf ("Inserire le coordinate dei punti\n");
  22. int i;
  23. for (i=0; i<n; i++){
  24. fgets (buffer, sizeof(buffer), stdin);
  25. sscanf (buffer, "%f %f", &points[i].x, &points[i].y);
  26. }
  27. printf ("Punti inseriti:\n");
  28. for (i=0; i<n; i++)
  29. printf ("%f %f\n", points[i].x, points[i].y);
  30. float dist[n];
  31. printf ("Distanza dei punti dall'origine\n");
  32. for (i=0; i<n; i++){
  33. dist[i]=sqrt(pow(points[i].x,2)+pow(points[i].y,2));
  34. printf ("%f\n", dist[i]);
  35. }
  36. printf ("Inserire le coordinate dei vertici del rettangolo\n");
  37. struct coord a, b;
  38. fgets (buffer, sizeof(buffer), stdin);
  39. sscanf (buffer, "%f %f", &a.x, &a.y);
  40. fgets (buffer, sizeof(buffer), stdin);
  41. sscanf (buffer, "%f %f", &b.x, &b.y);
  42. printf ("Punti compresi nel rettangolo\n");
  43. for (i=0; i<n; i++){
  44. if (points[i].x>=a.x && points[i].x<=b.x){
  45. if (points[i].y<=a.y && points[i].y>=b.y)
  46. printf ("%f %f\n", points[i].x, points[i].y);
  47. }
  48. }
  49. float area=(b.x-a.x)*(a.y-b.y);
  50. printf ("Il rettangolo ha area %f\n", area);
  51. int j;
  52. float distanza, dist_max;
  53. dist_max=0;
  54. struct coord p1, p2;
  55. for (i=0; i<n; i++){
  56. for (j=0; j<n; j++){
  57. distanza=sqrt(points[i].x*points[j].x+points[i].y*points[j].y);
  58. if (distanza>dist_max){
  59. dist_max=distanza;
  60. p1.x=points[i].x;
  61. p1.y=points[i].y;
  62. p2.x=points[j].x;
  63. p2.y=points[j].y;
  64. }
  65. }
  66. }
  67. printf ("I due punti piu' lontani sono\n%f %f\n%f %f\n", p1.x, p1.y, p2.x, p2.y);
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement