Đang chuẩn bị liên kết để tải về tài liệu:
C Programming for Scientists & Engineers phần 7

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Chương trình 5,2 xác định hai cấu trúc, cấu trúc hình tam giác và cấu trúc file_names. Hãy nhớ rằng các báo cáo xác định các cấu trúc là các kiểu dữ liệu mới có thể được sử dụng trong báo cáo kê khai. Ngoài ra, hãy nhớ rằng những cấu trúc này được định nghĩa bên ngoài của bất kỳ chức năng, | 84 c programming for scientists and engineers limit on the user. Secondly if any value greater than 20 is stored in no -fruit information in the for loop termination expression will not be consistent with the statements that the loop controls eventually leading to an uncontrolled failure of the program. Another problem that will occur is that the user must actually count the number of fruit that they think they can name before actually naming them. This is inconvenient for the user because they essentially have to do the same job twice. Also suppose that the user elects to name 15 fruits but can then only think of 7. The or loop will not end until 15 character strings have been supplied by the user.Thus for the program o continue the user must invent ome names. From this it should be dear that ahhough er loops can be used for controlling interaction with the user they are nor generally appropriate . y-ttr loops are most appropriate where a l of the information required to control the loop is known completely before the loop executes and the programmer can ensure that there will be no conflicts between the information used o control the loop and the Information urod by the statement s whin the loop as was the case in Program 4.1. Another example of this is shown in Program 4.3 which prints out a table of trigonometric hmcdon values. Program 4.3 - Trigonometric function display include stdio.h include math.h int main void double X pi 22.0 7.0 fprintffstdout X sin x cos x tan x n for x 0.0 X pi 2.0 x 0.1 fprintf stdout lf tf lf lf n X sin x cos x tan x return O In Program 4.3 a variable X of type double is declared and then used as a counter in the òr loop. The same declaration statement initializes pi using the result of a calculation so that its value is as accurate as the precision of the double data type will allow. Prior to the for loop fprintfis Team Fl Decisions and loops 85 called so that four column titles will appear on the screen. When the for loop starts X