Struct circle distance

PHOTO EMBED

Wed Jun 12 2024 03:19:24 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c #function #struct

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

struct Circle
{
	float radius;
	float x_position;
	float y_position;
	
};

float distance_between(struct Circle c1, struct Circle c2);

int main(void)
{
	struct Circle c1;
	struct Circle c2;

    float r1 = 0;
    float r2 = 0;
    scanf("%f", &r1);
    scanf("%f", &r2);
	c1.radius = r1;
	c2.radius = r2;
	c1.x_position = 11;
	c1.y_position = 22;
	c2.x_position = 4;
	c2.y_position = 6;

	float distance = distance_between(c1, c2);
	printf("distance between two circle is %f.", distance);

	return 0;
}

float distance_between(struct Circle c1, struct Circle c2)
{
    float distance;
    distance = sqrt( pow((c1.x_position - c2.x_position),2) + pow((c1.y_position - c2.y_position),2)) - c1.radius - c2.radius;
    return distance;
}

content_copyCOPY

Objective: Create a C program to calculate the distance between the edges of two circles given their radii and positions. Requirements Declare Circle Structure: Create a structure named Circle with the following members: Floating-point radius Floating-point x_position Floating-point y_position Declare and Define Function: Create a function named distance_between that takes two parameters, both of type struct Circle. The function should return a float value. The function must compute the distance between the edges of the two circles and return it. Formula: Distance= sqrt( (x1 - x2) ^2 + (y1 - y2)^2) - r1 - r2 Where: (x1,y1)(x1​,y1​) and (x2,y2)(x2​,y2​) are the coordinates of the centers of the two circles. r1r1​ and r2r2​ are the radius of the two circles. Input Result 2 3 distance between two circle is 12.464249.