Easy Tutorial
❮ C Exercise Example36 C Exercise Example54 ❯

C Language Example - Dividing Fish Among Five People

C Language Examples

A, B, C, D, and E went fishing together one night and were all exhausted by the early morning, so they each found a place to sleep.

When the sun was high, A woke up first and divided the fish into five portions, discarding one extra fish and taking his share.

B woke up next, also divided the fish into five portions, discarded one extra fish, and took his share.

C, D, and E woke up in turn and followed the same method to take their share of the fish.

How many fish did they catch at least, and how many fish did each person see when they woke up?

Example

#include <stdio.h>
int main(){
    int n,x,j,k,l,m;
    for(n=5;;n++){
        j=4*(n-1)/5;
        k=4*(j-1)/5;
        l=4*(k-1)/5;
        m=4*(l-1)/5;
        if(n%5==1&&j%5==1&&k%5==1&&l%5==1&&m%5==1){
            printf("At least they caught: %d fish\n",n);
            printf("Number of fish seen by each person: %d %d %d %d\n",j,k,l,m);
            break;
        }
    }
    return 0;
}

The output of the above example is:

At least they caught: 3121 fish
Number of fish seen by each person: 2496 1996 1596 1276

C Language Examples

❮ C Exercise Example36 C Exercise Example54 ❯