Task 6: The cake is a lie!
Task 6: The cake is a lie!
WARNING: This task requires knowledge of how to read from a file using fscanf and fprintf.
You're at a party and there's cake. Actually, ONE cake. Now the dilemma is to split it into N pieces for each of the N guests. But obviously, cakes have integer sizes and thus cannot be split into decimal-sized pieces. So there's gonna be leftovers. To avoid minimal waste, you cut as much integer pieces as possible, leaving the least amount of leftovers. Given the size of the cake and the number of guests, calculate size of each piece and leftovers.
Input:
This task will require you to read from a file. The file will contain two integers, S and N. S is the size of the cake and N is the number of guests.
Output:
Print out the size of each piece, then the size of the left over as a fraction. If there's no leftovers, no fraction is required.
Example:
Input:
55 12
Output:
4 7/12
Input:
100 10
Output:
10
You're at a party and there's cake. Actually, ONE cake. Now the dilemma is to split it into N pieces for each of the N guests. But obviously, cakes have integer sizes and thus cannot be split into decimal-sized pieces. So there's gonna be leftovers. To avoid minimal waste, you cut as much integer pieces as possible, leaving the least amount of leftovers. Given the size of the cake and the number of guests, calculate size of each piece and leftovers.
Input:
This task will require you to read from a file. The file will contain two integers, S and N. S is the size of the cake and N is the number of guests.
Output:
Print out the size of each piece, then the size of the left over as a fraction. If there's no leftovers, no fraction is required.
Example:
Input:
55 12
Output:
4 7/12
Input:
100 10
Output:
10
Similar topics
» Task 2: Lightposts
» Task 4: MasterCoder
» Task 1: Rectangle Area
» Task 3: Cave Troll
» Task 5: As easy as bagels
» Task 4: MasterCoder
» Task 1: Rectangle Area
» Task 3: Cave Troll
» Task 5: As easy as bagels
Permissions in this forum:
You cannot reply to topics in this forum