C programming language - the basic algorithm

C programming language - the basic algorithm

C language introduced in the previous two articles in the Getting Started program entry procedures 1 , entry procedures 2 , from the beginning of this article we will introduce the C programming language.
Today to introduce a characteristic and algorithm of algorithms.

The basic characteristics of the algorithm

Content algorithm contains two aspects: algorithm design and analysis of algorithms

Algorithm design is actually for a particular type of problem and design an implementation process. Algorithm has the following features:

  • Finite nature
  • Uncertainty
  • feasibility
  • Entry
  • Export

That we are in the design of algorithms to meet the above mentioned characteristics. Of course, the algorithm is good and bad, then we how to measure the pros and cons of an algorithm do?
Algorithm analysis is in fact an algorithm to measure the pros and cons, usually analyzed from the following aspects:

  1. Correctness
  2. readability
  3. Robustness
  4. Time complexity and space complexity

Expression algorithm

In describing an algorithm commonly used methods are: natural language, a flowchart, NS, etc. FIG.

natural language

This easy to understand natural language expression, we pass a specific example to find out.
Demand: any input number 3, wherein the minimum number is obtained.
(1) define four variables are a, b, c, and min.
Different (2) the size of the input three numbers are assigned to a, b, c.
(3) determining whether a is less than b, is less than, min value will be assigned to a, b or the value of the assigned min.
(4) determines whether less than c min, is less than, is executed (5), or the value of c is assigned min.
(5) Output min.
The benefits of this way of expression is easy to understand, but when it comes to complex algorithms of natural language it is not very convenient.

flow chart

It is a flowchart of a frame number to represent the different properties of the various operations, performed by flow lines to indicate the direction of the algorithm. He is characterized by visual image, which is widely used.
The following figure illustrates the flowchart of symbols and meanings
Write pictures described here

There are three basic configurations flowchart, i.e., sequential structure, and selecting structure of the cyclic structure.

  • Sequential structure: the structure is simple linear sequence structure

Write pictures described here

  • Structure selection: Select structure is called the branch structure

Write pictures described here

  • Loop structure: repeatedly perform a series of operations, know when termination condition is not satisfied.

Write pictures described here

Then we need above flowchart to say something

Write pictures described here

NS flow chart

NS is a flowchart of the entire algorithm written in a rectangular frame, eliminating the flow lines in the flowchart. Let's continue to see an example:
Demand: Enter a number to determine whether a prime number.

Write pictures described here

The basic characteristics and algorithms of representation of the algorithm to introduce over.


Past articles
C language learning portal 01
C language learning portal 02

If you think this article helpful to you, please forward it to more people

[ C language Chinese community ] is a C language video tutorial, learn dry knowledge focused on C programming language learners' notes, e-books, two computers and other information-sharing platform, featuring in-depth articles, share his dry goods category, class skills learning resources to help you study.
Here Insert Picture Description

Published 37 original articles · won praise 64 · views 30000 +

Guess you like

Origin blog.csdn.net/csdn_wangchong/article/details/79618829