



Preview text:
lOMoAR cPSD| 59078336
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING
PROGRAMMING FOR ENGINEERS LABORATORY COURSE ID: EE058IU LAB 04 Array
Full name: ……………………………………...…………...
Student ID: …………………………………...………….....
Class: …...…………………
Group: ……..………………..
Date: …...…………………………………………………... lOMoAR cPSD| 59078336
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING Table of Contents
I. OBJECTIVES ..................................................................................................................... 3
II. PRE-LAB PREPARATION ............................................................................................. 3
III. IN-LAB PROCEDURE .................................................................................................. 3 lOMoAR cPSD| 59078336
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING I. OBJECTIVES •
Write basic C programs using arrays and strings •
Calculate the length of arrays •
Traverse and search an array in multiple directions and intervals •
Explain C strings and their storage format
II. PRE-LAB PREPARATION
Read the theory carefully at home before coming to the class. III. IN-LAB PROCEDURE Exercise 1
Write a C program that reads an array size and elements of array values (float). Write your own
functions that has input is an array and output is min, max, average, respectively. And 2 functions
(print_forward and print_back_ward) to print this array forward and backward. Output: Array size: 5 Element[0]:7.1 Element[0]:2.5 Element[0]:5 Element[0]:3.8 Element[0]:1.5 Min array: 1.5 Max array: 7.1 Average: 3.98 Forward: 7.1 2.5 5 3.8 1.5 Backward: 1.5 3.8 5 2.5 7.1 Exercise 2
Write C program read input n & x integer number and generate random integer array that length is n and range from 0-10.
Write your own functions that has input is an array and output are sorted array in ascending order,
and descending order, respectively. And function that has input is number x and counts the occurrences of x in array. Output: Enter size of array:5 Enter x: 2 Original array: 1 8 2 4 2 Ascending order: 1 2 2 4 8
Descending order: 8 4 2 2 1 We found 2 times x occurrences. lOMoAR cPSD| 59078336
INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING Exercise 3
Write C program read input M & N integer number and Write 3 functions:
Function 1: generate random integer matrix. The input are M & N. The output is random matrix that
size is MxN and have value in range from 0-100.
Function 2: the input is matrix and output is the matrix that sort rows in ascending orders.
Function 3: the input is matrix and output is the matrix that sort columns descending orders. Output: M = 4 N = 3 Original matrix: 5 3 1 9 8 7 0 4 1 2 9 3 Ascending order in row: 1 3 5 7 8 9 0 1 4 2 3 9 Descending order in col: 7 8 9 2 3 9 1 3 5 0 1 4