One yuan per bottle of soda, two empty bottles can replace a bottle of soda, the existing 20 yuan, the maximum can drink how many bottles?

Source: Internet
Author: User

If this problem is not considered in C language programming, purely mathematical thinking, the problem is very simple. We can list a few, 2 yuan can drink 3 bottles, 3 yuan can drink 5 bottles, 4 yuan can drink 7 bottles, 5 Yuan can drink 9 bottles, we are not difficult to find if there is n yuan, you can drink 2*n-1 bottles. The problem is very simple.

#define N
int main ()
{
	printf ("Drink up to%d bottles \ n", 2*n-1);
	return 0;
}

This is a method that also has the logic to complete this question:

1 yuan per bottle of soda, two empty bottles for a bottle of soda. 2n-1 bottle (n yuan);
int main ()
{
	int money = 0;
	int count = 0;
	printf ("Please enter money:");
	scanf ("%d", &money);
	Count = money;
	while (1)
	{
		if (2!= 0)
		{
			count = count + money-1;
			break;
		else
		{Money
			= MONEY/2;
			Count + = money;
		}
	}
	printf ("Altogether can buy:%d\n", count);
	System ("pause");
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.