Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct Dimensions {
float radius;
};
struct Room* new_circular_room(float radius){
Dimensions* dimensions = malloc(sizeof(Dimensions));
dimensions->radius = radius;
Room* room = malloc(sizeof(Room));
room->dimensions = dimensions;
room->area = &circular_area;
return room;
}
float circular_area(struct Room *room) {
/* a circular room requires cutting a square carpet of length/width 2 * radius */
float radius = room->dimensions->radius;
return (2 * radius) * (2 * radius);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment