In this problem you must write a program that determines if two circles intersect each other. The input to your program will be the coordinates for the center of each circle, followed by the radius of each circle.

The output will state whether the circles overlap, do not overlap, or are tangential (i.e., tangential circles touch each other at just one common point).

**Example 1:**

Enter the coordinates and radius for circle 1: 10 10 3

Enter the coordinates and radius for circle 2: 10 6 1

The circles are tangential.

**Example 2:**

Enter the coordinates and radius for circle 1: 8 8 3

Enter the coordinates and radius for circle 2: 8 4 2

The circles overlap.

// @BEGIN_OF_SOURCE_CODE
#include <cstdio>
int square (int x)
{
return x * x;
}
// distance between a and b
int distance (int x1, int y1, int x2, int y2)
{
return square(x1 - x2) + square(y1 - y2);
}
int main (int argc, char *argv [])
{
int circle1X, circle1Y, circle1Radius;
printf ("Enter the coordinates and radius for circle 1: ");
scanf ("%d %d %d", &circle1X, &circle1Y, &circle1Radius);
int circle2X, circle2Y, circle2Radius;
printf ("Enter the coordinates and radius for circle 2: ");
scanf ("%d %d %d", &circle2X, &circle2Y, &circle2Radius);
int centerDistance = distance(circle1X, circle1Y, circle2X, circle2Y);
if ( centerDistance == circle1Radius + circle2Radius ) {
printf ("The circles are tangential.\n");
} else if ( centerDistance < circle1Radius + circle2Radius ) {
printf ("The circles overlap");
} else {
printf ("The circles do not overlap");
}
return 0;
}
// @END_OF_SOURCE_CODE

### Like this:

Like Loading...

*Related*

## Published by Shahab

Completed B.Sc in CSE, @United International University, Dhaka.
Currently working as Development Engineer, Android and iOS Application.
View all posts by Shahab

Your porgram wont work. You need not to square the distance… Check it out my program

import java.util.Scanner;

class Main {

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int cx = in.nextInt(), cy = in.nextInt(), cr = in.nextInt();

int dx = in.nextInt(), dy = in.nextInt(), dr = in.nextInt();

int distance = ( Math.abs( cx – dx) + Math.abs ( cy- dy) );

if( distance == cr + dr )

System.out.println(“The circles are tangential”);

else if( distance < cr + dr )

System.out.println("The circles overlap");

else

System.out.println("The circles do not overlap");

}

}

This code is bogus. Doesn’t give the required output.