C in Lab4 Section 15
C in Lab4 Section 15
Lab Exercises
Exercise Ex. 1 Ex. 2 Ex. 3
Mark /3 /3 /4
Total Mark / 10
Lab #4 Objectives
● counter- controlled loop: for and while statements
● 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.
Part I: Lab Tasks
Task 1
A. Fill in the blank such that the program prints numbers from 10 to 1
#include <stdio.h>
int main() {
for ( ; ; )
{
printf("%d ", i);
}
return 0;
}
#include <stdio.h>
void main()
{
}
Task 2
#include <stdio.h>
void main()
{
Task 3
Declare and array of size =11 (use define statement), then use for loop to initialize it to the first
11 odd number
#include <stdio.h>
void main()
}
PART II: Lab Excercises
Exercise 1
Exercise Objectives
✔ Declare initialize 1D array
✔ counter- controlled loop
Problem Description
Write a program that displays the number of vowel characters of a string. The program
should do the followings:
● In the main, create an array of chars and its size of 50. Then, initialize it to
“welcome to PSUT university”.
● Using loops, sends every character in the array to a function called isVowel() that
takes a char variable and return either zero or one. If the char is vowel (a, e, i, o,
u) then return one, otherwise return zero. Finally, prints the number of vowel
characters of the string in the main().
● Note:: your code must handle the case sensitive of characters.
Sample Output
Number of vowel characters is 9
Exercise 2
Exercise Objectives
✔ Use counter controlled loops.
Problem Description
Write a program that reads an integer of 6 digits and then return the average of them
using loops.
Sample Output
Problem Description
Write a C program that reads a character that represents the color of light traffic (G:
Green, Y: Yellow, and R: Red) and displays ”Stop”, “Slow down and wait” or “Go” for
each character.
The program should extract each character and send it to a function that uses a switch
statement based on the character and prints the corresponding word.
Sample Output