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

What is the program structure in C language?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "what is the program structure in C language". In daily operation, I believe that many people have doubts about what the program structure in C language is. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the program structure in C language?" Next, please follow the editor to study!

(1) sequence structure

The programming of sequential structure is the simplest, as long as the corresponding statements are written according to the order of solving the problem, and its execution order is from top to bottom.

For example: a = 3cr b = 5, now exchange the value of aforb, this problem is like exchanging two cups of water, of course, the third cup is used, if the third cup is c, then the correct procedure is:

C = a; a = b; b = c

The result of the execution is a = 5, b = c = 3, if the order is changed, it is written as:

A = b; c = a; b = c

Then the implementation result becomes a = b = c = 5, which can not achieve the desired goal, and beginners are most likely to make this mistake. The sequence structure can be used independently to form a simple and complete program. The common input, calculation and output three-step program is the sequence structure, such as calculating the area of the circle. The sentence order of the program is to input the radius r of the circle, calculate s = 3.14159*r*r, and output the area of the circle s.

However, in most cases, the sequential structure is part of the program, together with other structures to form a complex program, such as the compound statement in the branch structure, the loop body in the loop structure, and so on.

(2) branching structure

Although the program with sequential structure can solve the problems of calculation and output, it can not make judgment and choice. The branch structure should be used for the problems that need to be judged before they are selected. The execution of the branch structure is to choose the execution path according to certain conditions, rather than strictly according to the physical order in which the statements appear. The key of the branch structure programming method is to construct the appropriate branch condition and analyze the program flow, and select the appropriate branch statement according to the different program flow.

The branch structure is suitable for the calculation with conditional judgment such as logic or relational comparison. When designing this kind of program, it is often necessary to draw its program flow chart first, and then write the source program according to the program flow, which separates the program design analysis from the language. it makes the problem simple and easy to understand. The program flow chart is the program execution flow chart drawn according to the problem-solving analysis.

Learning the branch structure should not be confused by the branch nesting, as long as the flow chart is drawn correctly and the function of each branch is clarified, the nested structure is not difficult. Nesting is just a branch that includes branch statements, not new knowledge. As long as you have a clear understanding of two branches, branch nesting is not difficult. Let me introduce some basic branching structures.

① if (conditional) {branch}

The branch body in this branch structure can be a statement, and "{}" can be omitted or multiple statements, that is, compound statements. It has two branch paths to choose, one is when the condition is true, execute the branch, otherwise jump over the branch, then the branch will not be executed. For example, to calculate the absolute value of x, according to the definition of the absolute value, we know that when x > = 0, its absolute value remains the same, but x

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