Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C++ to solve the problem of cattle grazing

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to use C++ to solve the cattle grazing problem. The content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe that everyone will gain something after reading this article on how to use C++ to solve the cattle grazing problem. Let's take a look.

The questions are as follows:

There is a pasture where the grass grows at a uniform rate every day. This pasture can feed 15 cattle for 20 days or 20 cattle for 10 days. So how many cattle can be fed by the amount of new grass every day in this pasture?

The ideas for solving mathematical problems are as follows:

Suppose a cow eats one portion of grass every day, then 15 cows eat grass for 20 days: 15 X 20 = 300 servings. 20 cattle grazed for 10 days: 20 X 10 = 200.

The former is based on the original grass, plus 20 days of new grass. The latter is based on the original grass, plus 10 days of new grass.

100 copies of 300-20000, 20-10-10 days.

It shows that if 100 pieces of grass grow in 10 days, then 10 parts of grass grow every day, which is enough for 10 cattle to eat one day.

The answer is that the pasture can produce enough grass to feed 10 cattle a day.

Continue to think: 10 cows eat the new grass every day, and the rest of the cattle eat the original grass, we can get:

Original grass: (15-10) X 20 = 100 or (20-10) X 10 = 100

It is interesting to convert mathematical problems into code implementation. As the children are new to some simple C++ code, so I wrote the simplest version.

The following is programmed in C++ language to implement the problem: int main () {int m1penn1bookm2recovern2scoop mi is the number of cattle, ni is the number of days of grazing corresponding to mi. Cin > > M1 > > N1 > m2 > N2; int x = (m1*n1-m2*n2) / (n1-n2); coutreturn 0;} this is the end of the article on "how to use C++ to solve the cattle grazing problem". Thank you for reading! I believe you all have a certain understanding of "how to use C++ to solve the cattle grazing problem". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 239

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report