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

Problem 4: Circles Overlap Write a program to determine whether or not two circl

ID: 3751054 • Letter: P

Question

Problem 4: Circles Overlap Write a program to determine whether or not two circles touch each other, overlap with each other, or not overlap with each other. your program should work like the following Ask the user to input the X-coordinate of the center of the first circle Ask the user to input the Y-coordinate of the center of the first circle Ask the user to input the radius of the first circle Ask the user to input the X-coordinate of the center of the second circle Ask the user to input the Y-coordinate of the center of the second circle Ask the user to input the radius of the second circle Based on these inputs, can you determine if the two circles are Touch each other Overlap with each other Not overlap with each other Show a proper message for each case est Your program using these 3 cases

Explanation / Answer

/* Logic for the solution of the program::
Distance between two points (x1,y1) and (x2,y2) is given by
Point_Distance= sqrt((x1-x2)^2+(y1-y2)^2)
If (x1,y1) and (x2,y2) are the centres of circle1 and circle2 respectively, then
Point_Distance will represent the distance between center of the circle.
If R1 and R2 are the radii of circle 1 & circle 2 respectively, then
there may be 3 cases:
1.R1+R2 == Point_Distance, circle 1 and circle 2 touch each other.
2.R1+R2 < Point_Distance, circles overlap with each other
3.R1+R2 > Point_Distance, circles do not overlap with each other.
In the program we Point_Distance as (x1-x2)*(x1-x2)+(y1-y2)*(y1-Y2), we don't
calculate square root, instead we take square of (R1+R2) for comparision */

#include<stdio.h>

int main()
{
   int x1,y1,x2,y2,Point_Distance,Center_Distance;
   float r1,r2;
   printf(" Enter the X-coordinate of the center of the First circle ");
   scanf("%d",&x1);
   printf(" Enter the Y-coordinate of the center of the First circle ");
   scanf("%d",&y1);
   printf("Enter the radius of the First circle ");
   scanf("%f",&r1);
   printf(" Enter the X-coordinate of the center of the Second circle ");
   scanf("%d",&x2);
   printf(" Enter the Y-coordinate of the center of the Second circle ");
   scanf("%d",&y2);
   printf("Enter the radius of the Second circle ");
   scanf("%f",&r2);
   Point_Distance=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
   Center_Distance=(r1+r2)*(r1+r2);
   if(Point_Distance==Center_Distance)
       printf(" The Circles Touch Each other.");
   else if(Point_Distance < Center_Distance)
       printf(" The Circles Overlap with each other.");
   else
       printf(" The Circles Do Not Overlap each other");
   return 0;

}

/*The three case for testing are::
Case 1: x1=0,y1=0,r1=5,x2=10,y2=0,r2=5, The circles touch each other
Case 2: x1=0,y1=0,r1=5,x2=10,y2=0,r2=6, The circles Overlap with each other
Case 3: x1=0,y1=0,r1=5,x2=10,y2=0,r2=3, The circles do not overlap with each other.

Feel free to ask any doubt.*/