Easy Tutorial
❮ C Examples Octal Decimal Convert C Function Gmtime ❯

C Practice Example 80

C Language Classic 100 Examples

Question: There is a pile of peaches on the beach, and five monkeys come to divide them. The first monkey divides the pile into five equal parts, with one extra. This monkey throws the extra one into the sea and takes one part. The second monkey divides the remaining peaches into five equal parts again, and there is one extra. It also throws the extra one into the sea and takes one part. The third, fourth, and fifth monkeys do the same. How many peaches were there at least originally on the beach?

Program Analysis: None.

Program Source Code:

Example

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015年 tutorialpro.org. All rights reserved.
//

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x, i=0, j=1;
    while(i&lt;5){
        x=4*j;
        for(i=0;i&lt;5;i++)
        {
            if(x%4!=0){break;}
            x=(x/4)*5+1;
        }
        j++;
    }
    printf("%d\n",x);

    return 0;
}

The above example outputs the result as:

3121

C Language Classic 100 Examples

❮ C Examples Octal Decimal Convert C Function Gmtime ❯