You are on page 1of 7

Programming 1

COMP 208
Chapter 4 – Page 151

4.6 State which values of the control variable x are printed


by each of the following for statements:

a) for ( x = 5; x <= 22; x += 7 ) {


printf( "%d\n", x );
}

b) for ( x = 12; x >= 2; x -= 3 ) {


printf( "%d\n", x );
}

2
Chapter 4 – Page 152

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

3
Chapter 4 – Page 152

4.12 (Calculating the Sum of Even Integers) Write a


program that calculates and prints the sum of the even
integers from 2 to 30.

4
Chapter 4 – Page 153

4.14 (Factorials) The factorial function is used frequently in


probability problems. The factorial of a positive integer n (written n!
and pronounced “n factorial”) is equal to the product of the positive
integers from 1 to n. Write a program that evaluates the factorials
of the integers from 1 to 5. Print the results in tabular format. What
difficulty might prevent you from calculating the factorial of 20?

5
Chapter 4 – Page 153

4.16 (Triangle-Printing Program) Write a program that prints the


following pattern

You might also like