136 Control Structures: Part 1 (Business web hosting) Chapter 4 4.9
136 Control Structures: Part 1 Chapter 4 4.9 What is wrong with the following while repetition structure? while ( z >= 0 ) sum += z; ANSWERS TO SELF-REVIEW EXERCISES 4.1 a) sequence, selection, repetition. b) if/else. c) counter-controlled or definite. d) sentinel, signal, flag or dummy. e) program control. f) Pseudocode. g) Keywords. h) empty. i) one. j) cast. 4.2 a) False. Pseudocode should convert easily into C# code. b) True. c) False. Some programmers argue that goto statements violate structured programming and cause considerable problems. d) True. e) True. f) False. The sequence structure is built into C#; lines of code execute in the order in which they are written, unless explicitly directed to do otherwise. g) True. h) False. Placing a semicolon after the condition in an if structure is usually a logic error. i) True. 4.3 x = x + 1; x += 1; ++x; x++; 4.4 a) z = x++ + y; b) if ( count > 10 ) Console.WriteLine( “Count is greater than 10″ ); c) total -= –x; d) q %= divisor; q = q % divisor; 4.5 a) int sum, x; b) x = 1; c) sum = 0; d) sum += x;or sum = sum + x; e) Console.WriteLine( “The sum is: ” + sum );or Console.WriteLine( “The sum is: {0}”, sum ); 4.6 1 // Calculate the sum of the integers from 1 to 10 2 3 using System; 4 5 class Calculate 6 { 7 static void Main( string[] args ) 8 { 9 int sum, x; 10 11 x = 1; 12 sum = 0; 13 14 while ( x <= 10 ) 15 { 16 sum += x++; 17 }
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services