0% found this document useful (0 votes)
35 views6 pages

C in Lab4 Section 15

This document outlines a lab assignment on structured programming in C. It includes 3 tasks to work on arrays, loops, and symbolic constants using C syntax. There are also 3 exercises - the first involves initializing an array, counting vowels, and passing characters to a function; the second reads a 6-digit integer and calculates the average of the digits; the third reads a character for a traffic light color and uses a function with a switch statement to print the corresponding word. The objective is to practice counter-controlled loops, arrays, and other C programming concepts.

Uploaded by

gpswk7y6vs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views6 pages

C in Lab4 Section 15

This document outlines a lab assignment on structured programming in C. It includes 3 tasks to work on arrays, loops, and symbolic constants using C syntax. There are also 3 exercises - the first involves initializing an array, counting vowels, and passing characters to a function; the second reads a 6-digit integer and calculates the average of the digits; the third reads a character for a traffic light color and uses a function with a switch statement to print the corresponding word. The objective is to practice counter-controlled loops, arrays, and other C programming concepts.

Uploaded by

gpswk7y6vs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

King Hussein Faculty of Computing Sciences

Department of Computer Science

Structured Programming Lab


In-Lab Assignment #4

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;
}

B. Rewrite the above program with while statement

#include <stdio.h>
void main()
{

}
Task 2

C. Declare an array and initialize it with the first 5 prime numbers

#include <stdio.h>
void main()
{

D. Declare an array and initialize it with name’s letters


#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

Enter an integer: 123456


Reversed number = 3.5
Exercise 3
Exercise Objectives
✔ Use counter controlled loops with functions and selection statements.

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

Enter number: RGYRY


Red Green Yellow Red Yellow

You might also like