"From problem to the program," the first and second chapters learning summary

"From problem to the program," the first and second chapters learning summary

And C programming language

Programming process

程序一词也来自生活,通常指完成某些事务的一种既定方式和过程。一个复杂的程序分解成为若干相对简单一些的程序,部分编程序时所需要掌握的恰恰就是这种工作方式。我们需要从问题的要求出发,从高层开始设计程序,并逐步分解程序功能。当将程序所需功能分解到一定的细节程度之后,就可以借助于程序语言的结构,描述程序工作中的细节步骤了。

C program

用 C 语言写的程序简称为 C 程序。
#include <stdio.h>
int main () {
printf("Good morning!\n");
return 0;
}

That the simple procedure can be divided into two basic parts: the first line is a special line, indicating that the standard procedures used C language functions provided by the system, this should reference the standard library stdio.h, in the fifth chapter for details. Lines under the empty row is part of the basic program, the program described in the work done. The significance of this program is to produce a line of output "Good morning!".
C language is a high-level programming language, written in C language source program is often referred to, people tend to use, writing and reading, but the computer can not be executed directly, because the computer can only recognize and execute a particular form of binary machine language program. To enable the computer to complete the work of a C source program described, this must first source (e.g., the simple example above) converted into a binary form of a machine language program, this conversion is done by the C system.

And calculate the data object

This chapter describes the C language in the wording of the provisions of the various data, how we express what we want to complete the task in the program. Including the introduction of an identifier, data type, operation, function.

The basic character identifier

A C program is a C language the basic character of the provisions in the form of sequences that are required. C language basic characters include:

  1. Numeric characters, 0,1,2,3,4,5,6,7,8,9;
  2. Case Latin: a ~ z, A ~ Z;
  3. Other printable (to display) characters (such as punctuation marks, operation symbol, brackets, etc.), comprising: ~% & * () _ + = {} [] :; " '<>,!.? / |.
  4. There are some special characters, such as spaces, line breaks, tabs, and so on. Spaces, line breaks, tabs, etc. collectively referred to as blank characters. Whitespace characters in the program is mainly used to separate other ingredients.
    Programs often need to define a few things to use everywhere. In order to establish a link between the definition and use, expressed different positions with the same object, the basic way is to program objects named by name established between the definition and use of contact between different uses of the same object. For this need, C language defines the written form of the name. Program name called identifiers. An identifier is a continuous sequence of alphanumeric characters, wherein the characters have no gaps, but requires the first character must be a letter. For convenience, C language special provisions will underscore character "_" is also viewed as a letter.

    Data types

    Integer type int long integer type long int
    real types: single-precision floating point type float type double double length precision type long double
    character type char, long special characters: the newline character '\ n-', double-quote character '' ', a single quote 'character, the backslash character' \ '.

#include <stdio.h>
int main () {
   printf("Welcome\nto\nBeijing!\n");
   printf( "%d+%d=%d\n"2,3,5);
   printf("len:%f, width:%f, area:%f\n", 2.2, 3.5, 7.7);
   return 0;
}

The output of the above procedure:
available for purchase
to
Beijing
2 +. 3. 5 =
len: 2.200000, width: 3.500000, Area: 7.700000

Operators

C语言的算术运算度一共有5个,如下表。

5个算术运算符的运算优先级如下.

具有相同优先级的运算符相邻出现时,C语言规定一元算术运算符自右向左结合;二元算术运算符自左向右结合,优先级相同时左边的运算符先计算。如果用括号括起表达式中的某个部分,括号里面的表达式将先行计算,得到的结果再参与括号外面的其他计算。
当某个运算符的运算对象具有不同类型时,就出现了混合类型计算。例如表达式:3.27 + 201,这里的一个运算对象是 double 类型,而另一个运算对象是 int 类型。当表达式计算中遇到混合类型计算时,处理方式是转换某个(或两个)运算对象的值,先从计算对象转换出相同类型的值,然后再做实际计算。这种由混合类型计算引起的类型转换称为算术运算中的自动类型转换。“自动”的意思就是说这种转换不需要在程序里明确写出。自动类型转换的基本原则是把表示范围小的类型的值转换到表示范围大的类型的值。按规定,几个算术类型转换的排列顺序从小到大是:int  long  float  double  long double.

Function and its use

To use a function, just you need to know:

  1. The name of the function,
  2. Use the function,
  3. This function completes what calculations can give any results.
    Using the function in the general form of the expression is:
    function name (actual parameter)
    function name (actual parameters, actual parameters)
#include <stdio.h>
#include <math.h>
int main () {
printf("Area of the triangle: %fm^2\n",
3.5 * 4.72 * sin(37.0 / 180 * 3.1416) / 2);
return 0;
}

In the above-described function is required lengths of two adjacent sides 3.5 and 4.72 m, the angle of the sides of a triangular area of ​​37 degrees.

Guess you like

Origin www.cnblogs.com/2499mly/p/11801638.html