$25
Objectives:
At the end of the class the students should be able to:
use repetition statements in C programs
Exercise 1:
Write a C program that uses while loop to print the following table of values. Use the tab escape sequence in the printf statement to separate the column with tabs.
N 10*N 100*N 1000*N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000
6 60 600 6000
7 70 700 7000
8
80 800 8000
9 90 900 9000
10 100 1000 10000
Exercise 2:
The factorial of a nonnegative integer n is written n! and is defined as follows:
n! = n * (n - 1) * (n - 2) * ……1
and n! = 1 (for n = 0)
For example, 5! = 5 * 4 * 3 * 2 * 1, which is 120
Write a C program that reads a nonnegative integer and computes and print its factorial using a while loop.
1
Year 1
Lab Sheet3
IT1010 – Introduction to Programming
Semester 1, 2020
Exercise 3
Write a program that prints the following patterns separately. Use for loop to generate the patterns. All asterisks (*) should be printed by a single printf statements.
( a ) (b) (c) ( d )
* ********** ********** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
********** * * **********