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 solve the problem of catching Traffic Accidents with C language

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

Share

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

This article mainly introduces "how to solve the problem of catching traffic troublemakers with C language". In daily operation, I believe many people have doubts about how to solve the problem of catching traffic troublemakers with C language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for everyone to answer the doubts about "how to solve the problem of catching traffic troublemakers with C language". Next, please follow the editor to study!

1. Problem description

A truck violated traffic regulations, hit someone and ran away. Three people at the scene witnessed the incident, but none of them remembered the car number, only some characteristics of the car number.

A said: the first two digits of the license plate are the same

B said: the last two digits of the license plate are the same, but different from the first two.

C is a mathematician, he said: the car number of four digits happens to be the square of an integer.

Please get the car number according to the above clues.

two。 Topic analysis

According to the requirements of the topic, create a 4-digit integer with the same number in the first two digits, the same in the last two digits and different from each other, and then determine whether the integer is the square of another integer.

That is, to find a four-digit a 1, a 2, a 3, a 4, which meets the following conditions:

3. Algorithm design

The problem is a numerical problem, which is used to solve indefinite equations.

For this kind of problem of solving indefinite equations, exhaustive cycle is generally used.

First of all, design a double-layer cycle to enumerate all the four-digit license plates composed of the first two digits and the last two digits.

Then in the innermost layer, enumerate all the squared values that are four digits and less than the number of the license plate.

Finally, it is judged whether the number is equal to the license plate, and if so, the license plate is printed.

4. Process framework

The program flow chart is as follows

Determine whether the license plate k is the square of an integer.

Again using the loop to achieve, the loop variable temp squared with the license plate k comparison, if equal to find the license plate number.

In the optimization algorithm, the initial value of temp should start at 31, because the square of the number less than 30 is less than 4 digits, so the layer loop is the innermost loop, which is done for each license plate.

5. Code implementation

Complete code?

Int main () {int I = 0 Trachaplash I represents the first two license plate numbers int j = 0 Trachap j represents the last two license plate numbers int k = 0 Trachampact k represents license plate number int temp = 0; for (I = 0; I)

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: 0

*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