Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
chương trình đi qua một danh sách các trái phiếu và cho biết thêm các biểu tượng để danh mục đầu tư trái phiếu có năng suất dưới 10% hoặc không có một đồng tiền JPY và trưởng thành hơn 5 năm. Ví dụ 2.7: các nhà khai thác hợp lý và có điều kiện if (((Năng suất 5) portfolio.Add (biểu tượng)); | The Basics of C 7 program goes through a list of bonds and adds the symbol to the portfolio where the bond has a yield of less than 10 or does not have a currency of JPY and a maturity of more than 5 years. Example 2.7 Conditional and logical operators if Yield 0.1 CCY JPY mat 5 portfolio.Add symbol 2.1.5 Operator precedence In C as in most other programming languages the operators have different rules of precedence. These are that the comparative operators work from left to right while the assign operators are right to left. Consider the expression in Example 2.8 where there is a mathematical operator and an assign operator. What the programmer is trying to achieve is to assign the results of the rate divided by the number of days to a variable yield. Example 2.8 Operator precedence double yield rate numberOfDays The first operator that is performed is rate numberOfDays and the result is then assigned to the variable yield. This has worked because the operator precedence is such that the calculation operation is performed before the assign operator. Now consider Example 2.9 where there are two mathematical operators the order in which the divide or the multiply are performed is important to the result. Example 2.9 Precedence of logical operators double yield rate numberOfDays 100 The mathematical operations are performed from left to right with the calculation of rate numberOfDays being executed before being multiplied by 100. In Example 2.10 the same calculation is done but this time the brackets take higher precedence meaning that the number of days multiplied by 100 is done before the division. Example 2.10 Precedence of logical operators with brackets double yield rate numberOfDays 100 8 Applied C in Financial Markets The best way to perform complicated calculations is either to break the calculation down into a number of steps or surround the blocks with brackets this reaps rewards when it comes to maintenance of the code. In Example 2.11 the calculation .