# 2.19 (Arithmetic, Largest Value and Smallest Value) Write a program ```2.19 (Arithmetic, Largest Value and Smallest Value) Write a program that inputs three different
integers from the keyboard, then prints the sum, the average, the product, the smallest and the
largest of these numbers. Use only the single-selection form of the if statement you learned in this
chapter. The screen dialogue should appear as follows:
Input three different integers: 13 27 14
Sum is 54
Average is 18
Product is 4914
Smallest is 13
Largest is 27
2.20 (Diameter, Circumference and Area of a Circle) Write a program that reads in the radius
of a circle and prints the circle’s diameter, circumference and area. Use the constant value 3.14159
for PI. Perform each of these calculations inside the printf statement(s) and use the conversion
specifier
%f. [Note: In this chapter, we have discussed only integer constants and variables. In Chapter 3
we’ll discuss floating-point numbers, i.e., values that can have decimal points.
2.24 (Odd or Even) Write a program that reads an integer and determines and prints whether it
is odd or even. [Hint: Use the remainder operator. An even number is a multiple of two. Any multiple
of two leaves a remainder of zero when divided by 2.
3.11 Identify and correct the errors in each of the following. [Note: There may be more than one
error in each piece of code.]
a) if ( age &gt;= 65 );
printf( &quot;Age is greater than or equal to 65\n&quot; );
else
printf( &quot;Age is less than 65\n&quot; );
b) int x = 1, total;
while ( x &lt;= 10 ) {
total += x;
++x;
}
c) While ( x &lt;= 100 )
total += x;
++x;
d) while ( y &gt; 0 ) {
printf( &quot;%d\n&quot;, y );
++y;
}
3.13 What does the following program print?
#include &lt;stdio.h&gt;
2
3 int main( void )
4{
5 int x = 1, total = 0, y;
6
7 while ( x &lt;= 10 ) {
8 y = x * x;
9 printf( &quot;%d\n&quot;, y );
10 total += y;
11 ++x;
12 } /* end while */
13
14 printf(&quot;Total is %d\n&quot;, total);
15 return 0;
16 } /* end main */
3.22 (Predecrementing vs. Postdecrementing) Write a program that demonstrates the difference
between predecrementing and postdecrementing using the decrement operator --.
3.23 (Printing Numbers from a Loop) Write a program that utilizes looping to print the numbers
from 1 to 10 side by side on the same line with three spaces between numbers.
4.2 State whether the following are true or false. If the answer is false, explain why.
a) The default case is required in the switch selection statement.
b) The break statement is required in the default case of a switch selection statement.
c) The expression (x &gt; y &amp;&amp; a &lt; b) is true if either x &gt; y is true or a &lt; b is true.
d) An expression containing the || operator is true if either or both of its operands is true.
4.3 Write a statement or a set of statements to accomplish each of the following tasks:
a) Sum the odd integers between 1 and 99 using a for statement. Assume the integer variables
sum and count have been defined.
b) Print the value 333.546372 in a field width of 15 characters with precisions of 1, 2, 3, 4
and 5. Left justify the output. What are the five values that print?
c) Calculate the value of 2.5 raised to the power of 3 using the pow function. Print the result
with a precision of 2 in a field width of 10 positions. What is the value that prints?
d) Print the integers from 1 to 20 using a while loop and the counter variable x. Assume
that the variable x has been defined, but not initialized. Print only five integers per line.
[Hint: Use the calculation x % 5. When the value of this is 0, print a newline character,
otherwise print a tab character.]
e) Repeat Exercise 4.3 (d) using a for statement.
4.4 Find the error in each of the following code segments and explain how to correct it.
a) x = 1;
while ( x &lt;= 10 );
x++;
}
b) for ( y = .1; y != 1.0; y += .1 )
printf( &quot;%f\n&quot;, y );
c) switch ( n ) {
case 1:
printf( &quot;The number is 1\n&quot; );
case 2:
printf( &quot;The number is 2\n&quot; );
break;
default:
printf( &quot;The number is not 1 or 2\n&quot; );
break;
}
d) The following code should print the values 1 to 10.
n = 1;
while ( n &lt; 10 )
printf( &quot;%d &quot;, n++ );
4.5 Find the error in each of the following. (Note: There may be more than one error.)
a) For ( x = 100, x &gt;= 1, x++ )
printf( &quot;%d\n&quot;, x );
b) The following code should print whether a given integer is odd or even:
switch ( value % 2 ) {
case 0:
printf( &quot;Even integer\n&quot; );
case 1:
printf( &quot;Odd integer\n&quot; );
}
c) The following code should input an integer and a character and print them. Assume the
user types as input 100 A.
scanf( &quot;%d&quot;, &amp;intVal );
charVal = getchar();
printf( &quot;Integer: %d\nCharacter: %c\n&quot;, intVal, charVal );
d) for ( x = .000001; x == .0001; x += .000001 ) {
printf( &quot;%.7f\n&quot;, x );
}
e) The following code should output the odd integers from 999 to 1:
for ( x = 999; x &gt;= 1; x += 2 ) {
printf( &quot;%d\n&quot;, x );
}
f) The following code should output the even integers from 2 to 100:
counter = 2;
Do {
if ( counter % 2 == 0 ) {
printf( &quot;%d\n&quot;, counter );
}
counter += 2;
} While ( counter &lt; 100 );
g) The following code should sum the integers from 100 to 150 (assume
to 0):
total is
initialized
for ( x = 100; x &lt;= 150; x++ ); {
total += x;
}
4.7 Write for statements that print the following sequences of values:
a) 1, 2, 3, 4, 5, 6, 7
b) 3, 8, 13, 18, 23
c) 20, 14, 8, 2, –4, –10
d) 19, 27, 35, 43, 51
4.8 What does the following program do?
1 #include &lt;stdio.h&gt;
2
3 /* function main begins program execution */
4 int main( void )
5{
6 int x;
7 int y;
8 int i;
9 int j;
10
11 /* prompt user for input */
12 printf( &quot;Enter two integers in the range 1-20: &quot; );
13 scanf( &quot;%d%d&quot;, &amp;x, &amp;y ); /* read values for x and y */
14
15 for ( i = 1; i &lt;= y; i++ ) { /* count from 1 to y */
16
17 for ( j = 1; j &lt;= x; j++ ) { /* count from 1 to x */
18 printf( &quot;@&quot; ); /* output @ */
19 } /* end inner for */
20
21 printf( &quot;\n&quot; ); /* begin new line */
22 } /* end outer for */
23
24 return 0; /* indicate program ended successfully */
25 } /* end function main */
4.26 (Calculating the Value of PI ) Calculate the value of PIfrom the infinite series

Print a table that shows the value of approximated by one term of this series, by two terms, by
three terms, and so on. How many terms of this series do you have to use before you first get 3.14?
3.141? 3.1415? 3.14159?
4.36 What does the following program segment do?
1 for ( i = 1; i &lt;= 5; i++ ) {
2 for ( j = 1; j &lt;= 3; j++ ) {
3 for ( k = 1; k &lt;= 4; k++ )
4 printf( &quot;*&quot; );
5 printf( &quot;\n&quot; );
6}
7 printf( &quot;\n&quot; );
8}
```