c_winter_2019/circle.c

44 lines
958 B
C
Raw Permalink Normal View History

2020-01-31 14:49:37 +01:00
#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;
}