-
Notifications
You must be signed in to change notification settings - Fork 0
/
circles.cpp
51 lines (50 loc) · 1.48 KB
/
circles.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// circles.cpp
// Daniel Shterev
#include <iostream>
#include <cmath>
using namespace std ;
int main()
{
int x1, y1, x2, y2, r1, r2, xz, yz ;
double p ;
cout << "Please enter coordinates to the first circle: " ;
cin >> x1 >> y1 ;
cout << "Please enter a radius to the first circle: " ;
cin >> r1 ;
cout << "Please enter coordinates to the second circle: " ;
cin >> x2 >> y2 ;
cout << "Please enter a radius to the second circle: " ;
cin >> r2 ;
if ( x1 >= x2 ) //checks which circle's central point is farther than the others
{
xz = x1 - x2 ;
}
else
{
xz = x2 - x1 ;
}
if ( y1 >= y2 ) //checks which circle's central point is higher than the other's
{
yz = y1 - y2 ;
}
else
{
yz = y2 - y1 ;
}
p = sqrt ( xz*xz + yz*yz ) ; //calculates distance between circles
if ( ( r1 + r2 ) > p ) // checks if sum of the radiuses is bigger than the distance between the circles
{
cout << "Circles cross each other" << endl ;
return 0 ;
}
if ( ( r1 + r2 ) == p ) // checks if sum of the radiuses is equal to the distance between the circles
{
cout << "Circles touch each other" << endl ;
return 0 ;
}
if ( ( r1 + r2 ) < p ) // checks if sum of the radiuses is smaller than the distance between the circles
{
cout << "Circles have no common tangents" << endl ;
return 0 ;
}
}