Current location - Training Enrollment Network - Mathematics courses - Mathematics required for senior one 3. The program software contained in the first chapter of the algorithm is preliminary.
Mathematics required for senior one 3. The program software contained in the first chapter of the algorithm is preliminary.
I go to school in Grade One.

If you want to see it, you can look at Tan Haoqiang's C language programming.

I will post some for you first.

C language version

At present, the most popular C language is as follows:

Microsoft c or Microsoft c

Borland Turbo C or Turbo C

At&T Company. temperature coefficient

These C language versions not only realize the ANSI C standard, but also make some extensions on this basis to make it more convenient and perfect.

Object-oriented programming language

On the basis of C, Bjarne Strou-strup of Bell Laboratories introduced C++ in 1983. C++ further expands and perfects C language and becomes an object-oriented programming language. The latest popular C++ versions are Borland C++4.5, Symantec C++6. 1 and Microsoft VisualC++ 2.0. C++ put forward some deeper concepts. These object-oriented concepts supported by c++ can easily map the problem space directly to the program space, which provides programmers with a way of thinking and programming different from traditional structured programming. Therefore, it also increases the complexity of the whole language and is difficult to master.

C and c++

But C is the foundation of C++, and C++ and C are compatible in many aspects. Therefore, if you master C language and further study C++, you can learn object-oriented language with familiar grammar, thus achieving the goal of getting twice the result with half the effort.

Structural characteristics of c source program

In order to illustrate the characteristics of the C language source program structure, first look at the following program. These programs go from the simple to the deep, which embodies the characteristics of the composition structure of C language source programs. Although the relevant contents are not introduced, we can learn the basic part and writing format of a C source program from these examples. Master ()

{printf ("Hello, www.vcok.com, C language world! \ n ");

}

Main is the function name of the main function, indicating that this is a main function. Every C source program must have one and only one main function. Function call statement, the function of printf is to send the content to be output to the display for display. The printf function is a standard function defined by the system and can be directly called in the program.

# Including

# Including

Master ()

{

Double x, s;

Printf ("Enter number: \ n");

scanf("%lf ",& ampx);

s = sin(x);

Printf (sine of "%lf is %lf\n", x, s);

}

Comment per line

Included files are called files. File with command extension. Also called header file or header file.

Define two real variables for later programs.

Display prompt information

Get a real number x from the keyboard

Find the sine of x and assign it to the variable s.

Display program running results

End of main function

The function of the program is to input a number X from the keyboard, find the sine value of X, and then output the result. The two lines before main () are called preprocessing commands (see later). There are several other preprocessing commands. The include here is called a file inclusion command, which means adding angle brackets or quotation marks.

It should be noted that the C language stipulates that the functions of scanf and printf can omit the include command of their header files. Therefore, in this example, you can also delete the include command #include in the second line. Similarly, in the example 1. 1, the printf function is used and the include command is omitted.

In the main function body of the example, it is divided into two parts, one is the explanation part and the other is the execution part. Description refers to the type description of variables. No variables are used in the example, so there is no explanation. C language stipulates that all variables used in the source program must be interpreted before use, otherwise there will be errors. This is a feature of compiled high-level programming language, which is different from interpreted BASIC language. The explanation part is an important part of the structure of C source program. In this example, two variables x, s are used to represent the input independent variable and the function value of sin. Because the sin function requires that these two variables must be double-precision floating-point types, the type specifier double is used to describe these two variables. The four-behavior execution part after the description part or the execution sentence part is used to complete the function of the program. The first line of the execution part is the output statement, which calls the printf function to output the prompt string on the display, requiring the operator to input the value of the independent variable X. The second line is to input a statement, call the scanf function, accept the number input on the keyboard and store it in the variable X. The third line is to call the sin function to send the function value to the variable S. The fourth line is to output the value of the variable S by the printf function, that is, the sine value of X. The program ends.

Printf ("Enter number: \ n");

scanf("%lf ",' c 10f 10 & amp; x);

s = sin(x);

Printf ("sine of% lf is %lf\n", "C 10F 10x, s");

When running this program, the number of prompt string input is given on the display screen, which is completed by the first line of the execution part. When prompted, the user types a number from the keyboard, such as 5, presses Enter, and then gives the calculation result on the screen.

Input and output functions

The input and output functions scanf and printf are used in the first two examples, and we will introduce them in detail in Chapter 3. Here, we briefly introduce their formats for the following use. Scanf and printf are called format input function and format output function respectively. It means to input and output values in a specified format. Therefore, the parameter list of these two functions in brackets is composed of the following two parts: "format control string", and the format control string of the parameter list is a string that must be enclosed in double quotation marks, indicating the data type of input and output. Various types of format representations can be found in Chapter 3. In the printf function, unformatted control characters can also appear in the format control string, and then the original text is printed on the display screen. The number of inputs or outputs is given in the parameter table. When there are multiple quantities, separate them with commas. For example:

Printf (sine of "%lf is %lf\n", x, s);

Where %lf is a format character, which means it is treated as a double-precision floating-point number. It appears twice in the format string, corresponding to two variables x and s, and the rest of the characters are unformatted characters, which are output on the screen as they are.

int max(int a,int b);

main(){

int x,y,z;

Printf ("Enter two numbers: \ n"); scanf("%d%d ",& ampx & amp; y);

z=max(x,y);

printf("maxmum=%d ",z);

}

int max(int a,int b){

If (a>b) returns a; Otherwise return to b;

}

This function is used to input two integers and output the largest one.

/* Function description */

/* Main function */

/* Variable Description */

/* Enter x, y values */

/* Call the max function */

/* Output */

/* Define the maximum function */

/* Returns the result to the tonic function */

In the above example, the function of the program is that the user inputs two integers and outputs a larger number after the program is executed. This program consists of two functions, the main function and the max function. There is a parallel relationship between functions. Other functions can be called from the main function. The max function is used to compare two numbers and then return the larger number to the main function. Max function is a user-defined function. So the instruction is given in the main function (the third line of the program). It can be seen that in the description part of the program, there can be not only variable description, but also function description. The details of this function will be introduced in Chapter 5. The content enclosed by/* and */after each line of the program is the comment part, and the program does not execute the comment part.

The execution process of the program in the above example is as follows: first, a prompt string is displayed on the screen, asking the user to enter two numbers. After entering the car, the scanf function statement receives these two numbers and sends them to the variables X and Y, and then calls the max function to pass the values of X and Y to the parameters A and B of the max function. Compare the sizes of a and b in the max function, return the larger value to the variable z of the main function, and finally output the value of z on the screen.

Structural characteristics of c source program

The source program in 1.C language can be composed of one or more source files.

2. Each source file can be composed of one or more functions.

3. No matter how many files a source program consists of, it has one and only one main function, namely the main function.

4. There can be preprocessing commands in the source program (include command is just one of them), and the preprocessing commands should usually be placed in front of the source file or source program.

5. Every description and statement must end with a semicolon. However, preprocessing commands, function headers and curly braces "}" cannot be followed by a plus sign.

6. Identifiers and keywords must be separated by at least one space. If there are obvious separators, you can also stop adding spaces to separate them.

Rules to follow when writing programs

Clear writing, easy to read, understand and maintain.