TAILIEUCHUNG - THEORY AND PROBLEMS OF PROGRAMMING WITH Second Edition phần 4

Bây giờ chúng ta giới thiệu các nhà điều hành dấu phẩy (,) được sử dụng chủ yếu kết hợp với tuyên bố cho. Toán tử này cho phép hai biểu thức khác nhau để xuất hiện trong tình huống mà chỉ biểu hiện thông thường sẽ được sử dụng. Ví dụ, nó có thể viết | CHAP. 6 CONTROL STATEMENTS 157 How many numbers g X 1 X -1 X 2 X 2 X a X 3 The average is This is the correct average of the positive numbers. Note that the average would be zero if all of the numbers had been averaged. THE COMMA OPERATOR We now introduce the comma operator which is used primarily in conjunction with the for statement. This operator permits two different expressions to appear in situations where only one expression would ordinarily be used. For example it is possible to write for expression 1a expression 1b expression 2 expression 3 statement where expression 1a and expression 1b are the two expressions separated by the comma operator where only one expression expression 1 would normally appear. These two expressions would typically initialize two separate indices that would be used simultaneously within the for loop. Similarly a for statement might make use of the comma operator in the following manner. for expression 1 expression 2 expression 3a expression 3b statement Here expression 3a and expression 3b separated by the comma operator appear in place of the usual single expression. In this application the two separate expressions would typically be used to alter . increment or decrement two different indices that are used simultaneously within the loop. For example one index might count forward while the other counts backward. EXAMPLE Searching for Palindromes A palindrome is a word phrase or sentence that reads the same way either forward or backward. For example words such as noon peep and madam are palindromes. If we disregard punctuation and blank spaces then the sentence Rise to vote sir is also a palindrome. Let us write a c program that will enter a line of text containing a word a phrase or a sentence and determine whether or not the text is a palindrome. To do so we will compare the first character with the last the second character with the next to last and so on until we have reached the middle of the text. The

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.