Chapter 5: Problem 2
Write a C++ statement or a set of \(\mathrm{C}++\) statements to accomplish each of the following: a) Sum the odd integers between 1 and 99 using a for statement. Assume the integer variables sum and count have been declared. b) Print the value 333.546372 in a 15 -character field with precisions of 1,2 and \(3 .\) Print each number on the same line. Left-justify each number in its field. What three values print? c) Calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions. What prints? d) Print the integers from 1 to 20 using a while loop and the counter variable x. Assume that the variable \(\times\) has been declared, but not initialized. Print only 5 integers per line. \([\text {Hint:} \text { When } \times \% 5 \text { is } 0,\) print a newline character; otherwise, print a tab character.] e) Repeat Exercise \(5.2(\mathrm{d})\) using a for statement.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.