Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<stdio.h> #include<math.h> int main() { int firstx; int firsty; int seco

ID: 3608902 • Letter: #

Question

#include<stdio.h>
#include<math.h>

int main()
{
    int firstx;
    int firsty;
    int secondx;
    int secondy;
    int thirdx;
    int thirdy;
    double distanceFS, distanceFT, TotalFirst;
    double distanceSF, distanceST, TotalSecond;
    double distanceTF, distanceTS, TotalThird;
    int house1, house2, house3;
   
    printf("What are the x and y coordinates of thefirst person's house? ");
    scanf("%d%d", &firstx, &firsty);
   
    printf("What are the x and y coordinates of thesecond person's house? ");
    scanf("%d%d", &secondx, &secondy);
   
    printf("What are the x and y coordinates of thethird person's house? ");
    scanf("%d%d", &thirdx, &thirdy);
   
    distanceFS == sqrt(pow((firstx-secondx),2) +pow((firsty-secondy),2));
    distanceFT == sqrt(pow((firstx-thirdx),2) +pow((firsty-thirdy),2));
    TotalFirst = distanceFS + distanceFT;
   
    distanceSF == sqrt(pow((secondx-firstx),2) +pow((secondy-firsty),2));
    distanceST == sqrt(pow((secondx-thirdx),2) +pow((secondy-thirdy),2));
    TotalSecond = distanceSF + distanceST;
   
    distanceTF == sqrt(pow((thirdx-firstx),2) +pow((thirdy-firsty),2));
    distanceTS == sqrt(pow((thirdx-secondx),2) +pow((thirdy-secondy),2));
    TotalThird = distanceTF + distanceTS;
   
    house1 = 1;
    house2 = 2;
    house3 = 3;
   
    if (TotalFirst < TotalSecond &&TotalFirst < TotalThird)   
      {
        printf("You should studyat person %d's house. ", house1 );
      }
    else if (TotalSecond < TotalFirst &&TotalSecond < TotalThird)
     {      
        printf("You should studyat person %d's house. ", house2 );
      }
    else if (TotalThird < TotalFirst &&TotalThird < TotalSecond)
      {
        printf("You should studyat person %d's house. ", house3 );
      }
          
   
    system("PAUSE");
    return 0;
}

Explanation / Answer

#include<stdio.h>
#include<math.h>
#include <conio.h>
int main()
{
    int firstx;
    int firsty;
    int secondx;
    int secondy;
    int thirdx;
    int thirdy;
    double distanceFS, distanceFT, TotalFirst;
    double distanceSF, distanceST, TotalSecond;
    double distanceTF, distanceTS, TotalThird;
    int house1, house2, house3;
   
    printf("What are the x and y coordinates of thefirst person's house? ");
    scanf("%d%d", &firstx, &firsty);
   
    printf("What are the x and y coordinates of thesecond person's house? ");
    scanf("%d%d", &secondx, &secondy);
   
    printf("What are the x and y coordinates of thethird person's house? ");
    scanf("%d%d", &thirdx, &thirdy);
   
    distanceFS == sqrt(pow((firstx-secondx),2) +pow((firsty-secondy),2));
    distanceFT == sqrt(pow((firstx-thirdx),2) +pow((firsty-thirdy),2));
    TotalFirst = distanceFS + distanceFT;
   
    distanceSF == sqrt(pow((secondx-firstx),2) +pow((secondy-firsty),2));
    distanceST == sqrt(pow((secondx-thirdx),2) +pow((secondy-thirdy),2));
    TotalSecond = distanceSF + distanceST;
   
    distanceTF == sqrt(pow((thirdx-firstx),2) +pow((thirdy-firsty),2));
    distanceTS == sqrt(pow((thirdx-secondx),2) +pow((thirdy-secondy),2));
    TotalThird = distanceTF + distanceTS;
   
    house1 = 1;
    house2 = 2;
    house3 = 3;
   
    if (TotalFirst < TotalSecond &&TotalFirst < TotalThird)   
      {
        printf("You should studyat person %d's house. ", house1 );
      }
    else if (TotalSecond < TotalFirst &&TotalSecond < TotalThird)
     {      
        printf("You should studyat person %d's house. ", house2 );
      }
    else if (TotalThird < TotalFirst &&TotalThird < TotalSecond)
      {
        printf("You should studyat person %d's house. ", house3 );
      }
          
    getch();
    return 0;
}