44 lines
958 B
C
44 lines
958 B
C
#include <stdio.h>
|
|
#include <math.h>
|
|
|
|
struct point {
|
|
float x;
|
|
float y;
|
|
};
|
|
|
|
struct circle {
|
|
struct point center;
|
|
float radius;
|
|
float circumference;
|
|
float area;
|
|
};
|
|
|
|
struct circle read_circle();
|
|
|
|
struct circle complete_circle(struct circle circle);
|
|
|
|
int main(void) {
|
|
struct circle circle;
|
|
circle = read_circle();
|
|
circle = complete_circle(circle);
|
|
|
|
printf("Circumference: %f\n", circle.circumference);
|
|
printf("Area: %f\n", circle.area);
|
|
return 0;
|
|
}
|
|
|
|
struct circle read_circle() {
|
|
struct circle circle;
|
|
printf("gimme da circ (<x,y> r): ");
|
|
char buf[256] = {0};
|
|
fgets(buf, sizeof(buf) / sizeof(buf[0]), stdin);
|
|
sscanf(buf, "<%f,%f> %f", &circle.center.x, &circle.center.y, &circle.radius);
|
|
return circle;
|
|
}
|
|
|
|
struct circle complete_circle(struct circle circle) {
|
|
circle.circumference = M_PI * 2 * circle.radius;
|
|
circle.area = M_PI * circle.radius * circle.radius;
|
|
return circle;
|
|
}
|