You are on page 1of 3

Rajarata University of Sri Lanka

Faculty of Applied Sciences


ICT 1402 – Principles of Program Design and Programming
Practical Number: 05
Practical Title: For Loop

Outline
 For Loop
 Increment & Decrement Operators
Outcome
 Write programs using for Loop.
 Handle the Increment and Decrement operators with the for loop

1. Try these programs to understand the Increment and Decrement operators.


Increment Operator
Post increment operator Pre increment operator

Decrement Operator
Post decrement operator pre decrement operator

2. For Loop Statement


Syntax:
for (initialize variable; condition; increment/decrement)
{
//this code block will execute until condition is true.
}
Try this program:

-Develop this program to display numbers from 1 to any given number


3. Write a program to print integers from -5 to 5.
4. Write a program to print integers from 10 to 1.
-Develop this program to display numbers from any given number to 1.
5. Try this program:

6. Write C program to print the following output


i. *
**
***
****
*****

ii. *****
****
***
**
*

iii. 666666
55555
4444
333
22
1
7. Write a program by using for loop to compute the sum of
1+2+3+ . . . +n (n should be a keyboard input)

8. The factorial of an integer n is the product of consecutive integer from 1 to n.


n!= n*(n-1)*…*1.
Write a c program by using for loop to compute and print the factorial of any given number
n.

You might also like