Latest web development tutorials

C Exercise Example 80

100 cases of classic C language 100 cases of classic C language

Title: There are a bunch of peaches, five monkeys to points on the beach. The first monkey peach average this pile is divided into five parts, one more, one more monkey thrown into the sea, took one. The second monkey the rest of the peaches and the average divided into five parts, one more, it also put more than one thrown into the sea, took a third, fourth, fifth monkeys are doing so and I asked the least number of original beach peach?

Program Analysis: None.

Source Code:

//  Created by www.w3big.com on 15/11/9.
//  Copyright © 2015年 本教程. All rights reserved.
//

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

Run the above example output is:

3121

100 cases of classic C language 100 cases of classic C language