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

55 526 0
THEORY AND PROBLEMS OF PROGRAMMING WITH Second Edition phần 4 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

157 CHAP. 61 CONTROL STATEMENTS How many numbers? 6 x=l x=A x=2 x=G x=2 x=S The average is 2.000000 This is the correct average of the positive numbers. Note that the average would be zero if all of the numbers had been averaged. 6.10 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 7a, expression 7b; expression 2; expression 3) statement where expression la and expression 7b are the two expressions, separated by the comma operator, where only one expression (expression I) 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 7; expression 2; expression 3a, expression 36) 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 (e.g., 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 6.32 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 comparisons will include punctuation and blank spaces. In order to outline a computational strategy, let us define the following variables. letter = a c ha rac t e r-type array containing as many as 80 elements. These elements will be the characters in the line of text. tag = an integer variable indicating the number of characters assigned to letter, excluding the escape character \O at the end. count = an integer variable used as an index when moving forward through letter. countback = an integer variable used as an index when moving backward through letter. flag = an integer variable that will be used to indicate a true/false condition. True will indicate that a palindrome has been found. loop = an integer variable whose value will always equal 1, thus appearing always to be true. The intent here is to continue execution of a main loop, until a particular stopping condition causes a breakout. I58 CONTROL STATEMENTS [CHAP. 6 We can now outline our overall strategy as follows. 1. Define the symbolic constants EOL (end-of-line), TRUE and FALSE. 2. Declare all variables and initialize loop (i.e., assign TRUE to loop). 3. Enter the main loop. (a) Assign TRUE to flag, in anticipation of finding a palindrome. (6) Read in the line of text on a character-by-character basis, and store in letter. (c) Test to see if the uppercase equivalents of the first three characters are E, N and D, respectively. If so, break out of the main loop and exit the program. (6) Assign the final value of count, less I, to tag. This value will indicate the number of characters in the line of text, not including the final escape character \ 0. (e) Compare each character in the first half of letter with the corresponding character in the second half. If a mismatch is found, assign FALSE to flag and break out of the (inner) comparison loop. (f) If flag is TRUE, display a message indicating that a palindrome has been found. Otherwise, display a message indicating that a palindrome has not been found. 4. Repeat step 3 (i.e., make another pass through the outer loop), thus processing another line of text. Here is the corresponding pseudocode. #include files #define symbolic constants main ( ) { /* declare all variables and initialize as required */ while (loop) { flag = TRUE; /* anticipating a palindrome */ /* read in a line of text and store in letter */ /* break out of while loop if first three characters of letter spell END (test uppercase equivalents) */ /* assign number of characters in text to tag */ for ((count = 0, countback = tag); count <= (tag - 1)/ 2;(++count, countback)) { if (letter[count] I= letter[countback]) { flag = FALSE; /* not a palindrome - break out of for loop */ 1 1 /* display a message indicating whether or not letter contains a palindrome */ The program utilizes the comma operator within a for loop to compare each character in the first half of letter with the corresponding character in the second half. Thus, as count increases from 0 to (tag - 1) / 2, countback decreases from tag to (tag / 2) + 1. Note that integer division (resulting in a truncated quotient) is involved in establishing these limiting values. CHAP. 61 CONTROL STATEMENTS 159 Also, observe that there will be two distinct comma operators within the for statement. Each comma operator and its associated operands are enclosed in parentheses. This is not necessary, but it does emphasize that each operand pair comprises one argument within the for statement. The complete C program is shown below. /* search for a palindrome */ #include <stdio.h> #include <ctype.h> #define EOL '\n' #define TRUE 1 #define FALSE 0 main ( ) { char letter[80]; int tag, count, countback, flag, loop = TRUE; /* main loop */ while (loop) { flag = TRUE; /* read the text */ printf("P1ease enter a word, phrase or sentence below:\n"); for (count = 0; (letter[count] = getchar()) I= EOL; ++count) 1 if ((toupper(letter[O]) == 'E') && (toupper(letter[l]) == IN') && (toupper(letter[2]) == ID')) break; tag = count - 1; /* carry out the search */ for ((count = 0, countback = tag); count <= tag/2; (++count, countback)) { if (letter[count] I= letter[countback]) { flag = FALSE; break; 1 } /* display message *I for (count = 0; count <= tag; ++count) putchar(letter[count]); if (flag) printf(" IS a palindrome\n\n"); else printf(" is NOT a palindrome\n\n")); 1 1 A typical interactive session is shown below, indicating the type of output that is generated when the program is executed. As usual, the user's responses are underlined. Please enter a word, phrase or sentence below: mu TOOT IS a palindrome 160 CONTROL STATEMENTS [CHAP. 6 Please enter a word, phrase or sentence below: FALSE FALSE is NOT a palindrome Please enter a word, phrase or sentence below: PULLUP PULLUP IS a palindrome Please enter a word, phrase or sentence below: ABLE W& I ERE I SAW ELBA ABLE WAS I ERE I SAW ELBA IS a palindrome Please enter a word, phrase or sentence below: - END Remember that the comma operator accepts two distinct expressions as operands. These expressions will be evaluated from left to right. In situations that require the evaluation of the overall expression (i.e., the expression formed by the two operands and the comma operator), the type and value of the overall expression will be determined by the type and value of the right operand. Within the collection of C operators, the comma operator has the lowest precedence. Thus, the comma operator falls within its own unique precedence group, beneath the precedence group containing the various assignment operators (see Appendix C). Its associativity is left to right. 6.11 THE goto STATEMENT The goto statement is used to alter the normal sequence of program execution by transferring control to some other part of the program. In its general form, the goto statement is written as goto label; where label is an identifier that is used to label the target statement to which control will be transferred. Control may be transferred to any other statement within the program. (To be more precise, control may be transferred anywhere within the current function. We will introduce functions in the next chapter, and discuss them thoroughly in Chapter 7.) The target statement must be labeled, and the label must be followed by a colon. Thus, the target statement will appear as label: statement Each labeled statement within the program (more precisely, within the current function) must have a unique label; i.e., no two statements can have the same label. EXAMPLE 6.33 The following skeletal outline illustrates how the goto statement can be used to transfer control out of a loop if an unexpected condition arises. /* main loop */ scanf ( "%f I" , &x) ; while (x <= 100) { if (x < 0) goto errorcheck; scanf ( "%f I" , &x) ; 1 161 CHAP. 61 CONTROL STATEMENTS /* error detection routine */ errorcheck: { printf ("ERROR - NEGATIVE VALUE FOR X"); In this example control is transferred out of the while loop, to the compound statement whose label is errorcheck, if a negative value is detected for the input variable x. The same thing could have been accomplished using the break statement, as illustrated in Example 6.28. The use of the break statement is actually the preferred approach. The use of the goto statement is presented here only to illustrate the syntax. All of the popular general-purpose programming languages contain a got o statement, though modern programming practice discourages its use. The goto statement was used extensively, however, in early versions of some older languages, such as Fortran and BASIC. The most common applications were: 1. Branching around statements or groups of statements under certain conditions. 2. Jumping to the end of a loop under certain conditions, thus bypassing the remainder of the loop during the current pass. 3. Jumping completely out of a loop under certain conditions, thus terminating the execution of a loop. The structured features in C enable all of these operations to be carried out without resorting to the goto statement. For example, branching around statements can be accomplished with the if - else statement; jumping to the end of a loop can be carried out with the continue statement; and jumping out of a loop is easily accomplished using the break statement. The use of these structured features is preferrable to the use of the goto statement, because the use of goto tends to encourage (or at least, not discourage) logic that skips all over the program whereas the structured features in C require that the entire program be written in an orderly, sequential manner. For this reason, use of the got o statement should generally be avoided. Occasional situations do arise, however, in which the goto statement can be useful. Consider, for example, a situation in which it is necessary to jump out of a doubly nested loop if a certain condition is detected. This can be accomplished with two if - break statements, one within each loop, though this is awkward. A better solution in this particular situation might make use of the goto statement to transfer out of both loops at once. The procedure is illustrated in the following example. EXAMPLE 6.34 Converting Several Lines of Text to Uppercase Example 6.19 presents a program to convert several successive lines of text to uppercase, processing one line of text at a time, until the first character in a new line is an asterisk (*). Let us now modifL this program to detect a break condition, as indicated by two successive dollar signs ($$) anywhere within a line of text. If the break condition is encountered, the program will print the line of text containing the dollar signs, followed by an appropriate message. Execution of the program will then terminate. The logic will be the same as that given in Example 6.19, except that an additional loop will now be added to test for two consecutive dollar signs. Thus the program will proceed as follows. 1. Assign an initial value of 1 to the outer loop index (linecount). 2. Carry out the following steps repeatedly, for successive lines of text, as long as the first character in the line is not an asterisk. (a) Read in a line of text and assign the individual characters to the elements of the char-type array letter. A line will be defined as a succession of characters that is terminated by an end-of-line (i.e, a newline) designation. (b) Assign the character count, including the end-of-line character, to tag. 162 CONTROL STATEMENTS [CHAP. 6 (c) Display the line in uppercase, using the library function toupper to carry out the conversion. Then display two newline characters (so that the next line of input will be separated from the current output by a blank line), and increment the line counter (linecount). (d) Test all successive characters in the line for two successive dollar signs. If two successive dollar signs are detected, then display a message indicating that a break condition has been found and jump to the terminating condition at the end of the program (see below). 3. Once an asterisk has been detected as the first character of a new line, write out "Good bye." and terminate the computation. Here is the complete C program. /* convert several lines of text to uppercase Continue conversion until the first character in a line is an asterisk (*). Break out of the program sooner if two successive dollar signs ($$) are detected */ #include <stdio.h> #include <ctype.h> #define EOL '\n' main ( ) t char letter[80]; int tag, count, linecount = 1; while ((letter(O1 = getchar()) I= I*') { /* read in a line of text */ for (count = 1; (letter[count] = getchar()) != EOL; ++count) 9 tag = count; I* display the line of text */ for (count = 0; count < tag; ++count) putchar(toupper(letter[count])); printf('\n\n"); ++linecount; /* test for a break condition */ for (count=l; count < tag; ++count) I$' if (letter[count-1J == && letter[count] == I$') { printf('BREAK CONDITION DETECTED - TERMINATE EXECUTION\n\n"); goto end; } I. end: printf ("Good bye") ; 1 It is interesting to compare this program with the corresponding program presented earlier, in Example 6.19. The present program contains an additional for loop embedded at the end of the while loop. This for loop examines consecutive pairs of characters for a break condition ($$), after the entire line has already been written out in uppercase. If a break condition is encountered, then control is transferred to the final printf statement ("Good bye') which is now labeled end. Note that this transfer of control causes a breakout from the if statement, the current for loop, and the outer while loop. You should run this program, using both the regular terminating condition (an asterisk at the start of a new line) and the breakout condition. Compare the results obtained with the output shown in Example 6.19. 163 CHAP. 61 CONTROL STATEMENTS Review Questions 6.1 What is meant by branching? 6.2 What is meant by selection? 6.3 What is meant by looping? Describe two different forms of looping. 6.4 Summarize the rules associated with the use of the four relational operators, the two equality operators, the two logical connectives and the unary negation operator. What types of operands are used with each type of operator? 6.5 How are char-type constants and char-type variables interpreted when used as operands with a relational operator? 6.6 How do expression statements differ from compound statements? Summarize the rules associated with each. 6.7 What is the purpose of the if - else statement? 6.8 Describe the two different forms of the if - else statement. How do they differ? 6.9 Compare the use of the if - else statement with the use of the 7 : operator. In particular, in what way can the 7 : operator be used in place of an if - else statement? 6.10 Summarize the syntactic rules associated with the if - else statement 6.11 How are nested if - else statements interpreted? In particular, how is the following interpreted? if e7 if e2 s7 else s2 Which logical expression is associated with the else clause? 6.12 What happens when an expression is encountered whose value is nonzero within a group of nested if - else statements? 6.13 What is the purpose of the while statement? When is the logical expression evaluated? What is the minimum number of times that a while loop can be executed? 6.14 How is the execution of a while loop terminated? 6.15 Summarize the syntactic rules associated with the while statement. 6.16 What is the purpose of the do - while statement? How does it differ from the while statement? 6.17 What is the minimum number of times that a do - while loop can be executed? Compare with a while loop and explain the reasons for the differences. 6.18 Summarize the syntactic rules associated with the do - while statement. Compare with the while statement. 6.19 What is the purpose of the for statement? How does it differ from the while statement and the do - while statement? 6.20 How many times will a for loop be executed? Compare with the while loop and the do - while loop. 6.21 What is the purpose of the index in a for statement? 6.22 Can any of the three initial expressions in the for statement be omitted? If so, what are the consequences of each omission? 6.23 Summarize the syntactic rules associated with the for statement. 6.24 What rules apply to the nesting of loops? Can one type of loop be embedded within another? 6.25 Can loops be nested within if - else statements? Can if - else statements be nested within loops? 6.26 What is the purpose of the switch statement? How does this statement differ from the other statements described in this chapter? 6.27 What are case labels (case prefixes)? What type of expression must be used to represent a case label? 6.28 Summarize the syntactic rules associated with the use of the switch statement. Can multiple case labels be associated with one alternative? 6.29 What happens when the value of the expression in the switch statement matches the value of one of the case labels? What happens when the value of this expression does not match any of the case labels? 1 64 CONTROL STATEMENTS [CHAP. 6 6.30 Can a default alternative be defined within a switch statement? If so, how would the default alternative be labeled? 6.3 1 Compare the use of the switch statement with the use of nested if - else statements. Which is more convenient? 6.32 What is the purpose of the break statement? Within which control statements can the break statement be included? 6.33 Suppose a break statement is included within the innermost of several nested control statements. What happens when the break statement is executed? 6.34 What is the purpose of the continue statement? Within which control statements can the continue statement be included? Compare with the break statement. 6.35 What is the purpose of the comma operator? Within which control statement does the comma operator usually appear? 6.36 In situations that require the evaluation of an expression containing the comma operator, which operand will determine the type and the value of the entire expression (i.e.y the expression to the left of the comma operator or the expression to the right)? 6.37 What is the precedence of the comma operator compared with other C operators? 6.38 What is the purpose of the goto statement? How is the associated target statement identified? 6.39 Are there any restrictions that apply to where control can be transferred within a given C program? 6.40 Summarize the syntactic rules associated with the goto statement. 6.41 Compare the syntax associated with statement labels with that of case labels (case prefixes). 6.42 Why is the use of the goto statement generally discouraged? Under what conditions might the goto statement be helpful? What types of usage should be avoided, and why? Discuss thoroughly. Problems 6.43 Explain what happens when the following statement is executed. if (abs(x) .Z xmin) x = (x > 0) 7 xmin : -xmin; Is this a compound statement? Is a compound statement embedded within this statement? 6.44 IdentifL all compound statements that appear within the following program segment. t sum = 0; do t scanf ( "%d" &i) ; if (i < 0) { i = -1; ++flag ; } sum += i; } while (i I= 0); 1 6.45 Write a loop that will calculate the sum of every third integer, beginning with i = 2 (icy calculate the sum 2 + 5 + 8 + 11 + - ) for all values of i that are less than 100. Write the loop three different ways. (a) Using a while statement. (6) Using a do - while statement. (c) Using a for statement. CHAP. 61 CONTROL STATEMENTS 165 6.46 Repeat Prob. 6.45 calculating the sum of every nth integer, beginning with the value assigned to nstart (i.e., for i = nstart, nstart + n, nstart + 2*n, nstart + 3*n, etc.). Continue the looping process for all values of i that do not exceed nstop. 6.47 Write a loop that will examine each character in a character-type array called text, and write out the ASCII equivalent (i.e, the numerical value) of each character. Assume that the number of characters in the array is specified in advance by the integer variable n. Write the loop three different ways. (a) Using a while statement. (b) Using a do - while statement. (c) Using a for statement. 6.48 Repeat Prob. 6.47 assuming that the number of characters in the array is not specified in advance. Continue the looping action until an asterisk (*) is encountered. Write the loop three different ways, as before. 6.49 Generalize Prob. 6.45 by generating a series of loops, each loop generating the sum of every j th integer, where j ranges from 2 to 13. Begin each loop with a value of i = 2, and increase i by j until i takes on the largest possible value that is less than 100. (In other words, the first loop will calculate the sum 2 + 4 + 6 + * - * + 98; the second loop will calculate the sum 2 + 5 + 8 + - * * + 98; the third loop will calculate the sum 2 + 6 + 10 + - - + 98; and so on. The last loop will calculate the sum 2 + 15 + 28 + - * * + 93.) Display the value of each complete sum. Use a nested loop structure to solve this problem, with one loop embedded within another. Calculate each sum with the inner loop, and let the outer loop control the value of j that is used by each pass through the inner loop. Use a for statement to structure the outer loop, and use each of the three different loop statements (while, do - while and for) for the inner loop. Develop a separate solution for each type of inner loop. 6.50 Write a loop that will generate every third integer, beginning with i = 2 and continuing for all integers that are less than 100. Calculate the sum of those integers that are evenly divisible by 5. Use two different methods to carry out the test. (a) Use the conditional operator (?:). (b) Use an if - else statement. 6.51 Generalize Prob. 6.50 by generating every nth integer, beginning with nstart (i.e., i = nstart , nstart + n, nstart + 2*n, nstart + 3*n, etc.). Continue the looping process for all values of i that do not exceed nstop. Calculate the sum of those integers that are evenly divisible by k, where k represents some positive integer. 6.52 Write a loop that will examine each character in a character-type array called text and determine how many of the characters are letters, how many are digits, how many are whitespace characters, and how many are other kinds of characters (e.g., punctuation characters). Assume that text contains 80 characters. 6.53 Write a loop that will examine each character in a character-type array called text and determine how many of the characters are vowels and how many are consonants. (Hint: First determine whether or not a character is a letter; if so, determine the type of letter.) Assume that text contains 80 characters. 6.54 Write a switch statement that will examine the value of an integer variable called flag and print one of the following messages, depending on the value assigned to flag. (a) HOT, if f lag has a value of 1 (b) LUKE WARM, if f lag has a value of 2 (c) COLD, if f lag has a value of 3 (d) OUT OF RANGE if f lag has any other value 6.55 Write a switch statement that will examine the value of a char-type variable called color and print one of the following messages, depending on the character assigned to color. (a) RED, if either r or R is assigned to color, (b) GREEN, if either g or G is assigned to color, 166 CONTROL STATEMENTS [CHAP. 6 (c) BLUE, if either b or B is assigned to color, (d) BLACK, if color is assigned any other character. 6.56 Write an appropriate control structure that will examine the value of a floating-point variable called temp and print one of the following messages, depending on the value assigned to temp. (a) ICE, if the value of temp is less than 0. (b) WATER, if the value of temp lies between 0 and 100. (c) STEAM, if the value of temp exceeds 100. Can a switch statement be used in this instance? 6.57 Write a for loop that will read the characters in a character-type array called text and write the characters backwards into another character-type array called backtext. Assume that text contains 80 characters. Use the comma operator within the for loop. 6.58 Describe the output that will be generated by each of the following C programs. (Note the similarities in the programs that are shown across from each other.) (a) #include estdio. h> (b) #include estdio. h> main ( ) main ( ) int i = 0, x = 0; int i = 0, x = 0; while (i < 20) { do { if (i % 5 == 0) { if (i % 5 == 0) { x += i; x++; printf("%d ", x); printf("%d ", x); 1 1 ++i ; ++i ; 1 } while (i < 20); printf('\nx = %d", x); printf("\nx = %d", x); } 1 (c) #include estdio. h> (d) #include <stdio.h> main ( ) main ( ) { { int i = 0, x = 0; int i = 0, x = 0; for (i = 1; i < 10; i *= 2) { for (i = 1; i < 10; ++i) { x++; if (i % 2 == 1) 'I, printf('%d x); x += i; 1 else printf("\nx = %d*, x); x- - * 'I, 1 printf ("%d x) ; 1 printf('\nx = %dm, x); [...]... : Value : Value : Value: Value : 7200.00 640 0.00 5600.00 48 00.00 40 00.00 3200.00 240 0.00 1600.00 800.00 0.00 Another c a l c u l a t i o n ? (Y/N) y E n t e r a new s e t o f data? (Y/N) Method: (1-SL 2-DDB 3-SYD) 2 D o u b l e - D e c l i n i n g - B a l a n c e Method End End End End End End End End End End o f Year of Year of of of of of of of of 1 2 3 4 5 Year Year Year Year 6 Year 7 Year 8 Year... subtraction, multiplication and division) Include a memory that can store one number Generate the following “pyramid” of digits, using nested loops 1 232 345 43 45 676 54 567898765 67890109876 7890123210987 89012 345 4321098 9012 345 676 543 2109 012 345 6789876 543 210 Do not simply write out 10 multidigit strings Instead, develop a formula to generate the appropriate output for each line Generate a plot of the function =... passed to srand (the value of the seed), but no arguments are passed to play Also, note that p l a y calls throw from two different places, and throw calls rand from two different places There are no arguments passed from p l a y to throw or from throw to rand However, rand returns a random integer to throw, and throw returns the value of an integer expression (the outcome of one throw of the dice)... replaced by OS, and all other characters (nonletters and nondigits) replaced by asterisks (*) Compile and execute the programs given in Examples 6.10,6.13 and 6.17, using the following 10 numbers: 27.5, 6.61 13 .4, 53.8, 29.2, 74. 5, 87.0, 39.9, 47 .7, 8.1, 63.2 Compile and execute the program given in Example 6.3 1 using the following 10 numbers: 27.5, -13 .4, 53.8, -29.2, 74. 5, 87.0, 39.9, -47 .7, -8.1, 63.2... 13 .4 3 0.08 53.8 4 0.10 29.2 5 0.10 74. 5 6 0.10 87.0 7 0.12 39.9 8 0.12 47 .7 9 0.12 8.1 10 0.12 [CHAP 6 63.2 (b) Calculate the cumulative product of a list of n numbers Test your program with the following six data items: 6.2, 12.3, 5.0, 18.8, 7.1, 12.8 (c) Calculate the geometric average of a list of numbers, using the formula xavg = ~ ~ 1 ~ *2* x X,J 1’ * 3 Test your program using the values of x... the previous version, is now handled through interactive dialog at the end of each set of calculations.) A separate function is now provided for each type of calculation In particular, the straight-line calculations are carried out within function s l , the double-declining-balance calculations within ddb, and the sum -of- the-years’-digits calculations within syd Each of these functions includes the... arguments v a l and n, which represent the original value of the item and its lifetime, respectively Note that the value of v a l is altered within each function, although the original value assigned to v a l remains unaltered within main It is this feature that allows repeated sets of calculations with the same input data The last function, w r i t e o u t p u t , causes the results of each set of calculations... use of the following relationships: ( i ) The day of the current year can be determined approximately as day = ( i n t ) (30 .42 * (mm - 1 ) ) + dd (ii) If mm == 2 (February), increase the value of day by 1 (iii) If mm > 2 and mm < 8 (March, April, May, June or July), decrease the value of day by 1 (iv) If yy % 4 == 0 and mm > 2 (leap year), increase the value of day by 1 ( v ) Increase the value of. .. 169 CONTROL STATEMENTS CHAP 61 Programming Problems 6.59 Modify the programs given in Examples 6.9,6.1 2and 6.16 so that each program does the following: (a) (6) 6.60 Read in a line of uppercase text, store it in an appropriate array, and then write it out in lowercase Read in a line of mixed text, store it in an appropriate array, and then write it out with all lowercase and uppercase letters reversed,... obtained with the arithmetic average of the same data Which average is larger? (6) Determine the roots of the quadratic equation a? x + bx + c = 0 using the well-known quadratic formula -b* J b 2 - 4ac a- 2a (see Example 5.6) Allow for the possibility that one of the constants has a value of zero, and that the quantity b2 - 4ac is less than or equal to zero Test the program using the following sets of data: . and the comma operator), the type and value of the overall expression will be determined by the type and value of the right operand. Within the collection of C operators, the comma operator. negation operator. What types of operands are used with each type of operator? 6.5 How are char-type constants and char-type variables interpreted when used as operands with a relational operator?. transferred within a given C program? 6 .40 Summarize the syntactic rules associated with the goto statement. 6 .41 Compare the syntax associated with statement labels with that of case labels

Ngày đăng: 13/08/2014, 18:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan