C language realizes a hundred dollars to buy a hundred chickens

One chicken is worth five, a female chicken is worth three, a chick is three, worth one, a hundred money buys a hundred chickens, ask, how many chickens, female chickens and chicks?
Solution: Let x, y, z represent the number of chickens, hens, and chicks respectively, then the following equations can be cited:
x+y+z=100; 5x+3y+z/3=100; where x is at most 10, y is 33 at most. As long as the program can meet the above two conditions, the output
code is as follows:

#include <stdio.h>
void main(void){
    
    
	int x,y,z;
	for(x=1;x<=20;x++){
    
    
		for(y=1;y<=33;y++){
    
    
			z=100-x-y;
			if((z%3==0)&&(5*x+3*y+z/3==100)){
    
    
				printf("cook=%d,hen=%d,chiken=%d\n",x,y,z);
			}
		}

	}

}

Guess you like

Origin blog.csdn.net/G_whang/article/details/113092933