You are on page 1of 3

King Hussein Faculty of Computing Sciences

Department of Computer Science

Structured Programming Lab


Pre-Lab #4– Counter-controlled loop

Student Name
Student University ID
Date

Pre-Lab #4 Experiment Experiment 4.1 Experiment 4.2


Mark /5 /5
Total Mark / 10

Lab #4 will cover the following topics:

● counter- controlled loop: for and while statements

● Examples (such as patterns)

● Defining 1D arrays (including array of characters )

● Initialize arrays (initializer list and using loops) and printing arrays

● Using the symbolic constant (#define) to specify an array’s size.

After studying the above concepts, answer the following questions, which are intended to
prepare you for the coming lab.
Experiment 4.1:
Experiment Objectives
✔ Understand the structure of the while loop

What does the following code segment display? Try each of these inputs: 12,
9, 3.
printf(“\nEnter a positive integer> “);
scanf(“%d”, &num);
while (num > 0) {
if(num % 2 == 0)
printf(“%d\t”, num);
num--;
} printf(“\n”);

Experiment 4.2:
Experiment Objectives
✔ Understand the structure of the for loop compared with while loop

Rewrite the program segment that follows, using a for loop:

product = 1;
i = 0;
while (i < n) {
scanf(“%d”, &a);
if (a != i)
product *= a;
++i;
}

Experiment 4.3:
Experiment Objectives
✔ Declare and initialize arrays

1. Declare an array and initialize it with the vowel characters

2. Declare and array and initialize it with the statement: “I Like C Programming”
3. Declare an array of size five and initialize it with zeros.

You might also like