1/19 beer and drinks

As the title~

Beer is 2.3 yuan per can and beverage is 1.9 yuan per can. Xiao Ming bought some beer and drinks for a total of 82.3 yuan.
We also know that he bought less beer than drinks. Please count how many cans he bought.

注意:答案是一个整数。

This question is relatively simple, just go to the code!

#include <stdio.h>
int main()
{
    
    
	double x1,y1;
	int x2,y2;//先定义啤酒数量价格和饮料的数量价格 
	x1=2.3;
	y1=1.9;
	for(x2=1.0;x1*x2<82.3;x2++)
	{
    
    
		for(y2=x2+1;y1*y2<=82.3;y2++)
		{
    
    
			if(x1*x2+y1*y2==82.3)
			{
    
    
				printf("%d",x2);
			}
		}
	}
}

The code runs as shown, the
Insert picture description here
answer is 11

Guess you like

Origin blog.csdn.net/FG_future/article/details/112826819