0% found this document useful (0 votes)
30 views11 pages

Practical Work 6 Labsheet

The document discusses a practical work session on arrays for an electrical engineering course. It includes definitions of arrays, declaring arrays, and examples of single and multi-dimensional arrays. It provides exercises for students to complete including fixing errors in code, completing code, and writing programs to manipulate and calculate values from arrays.

Uploaded by

Hxkim Official
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)
30 views11 pages

Practical Work 6 Labsheet

The document discusses a practical work session on arrays for an electrical engineering course. It includes definitions of arrays, declaring arrays, and examples of single and multi-dimensional arrays. It provides exercises for students to complete including fixing errors in code, completing code, and writing programs to manipulate and calculate values from arrays.

Uploaded by

Hxkim Official
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/ 11

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: ___________

DEC20012: FUNDAMENTAL PROGRAMMING

build programs written in C language for assigned mini project during


CLO2
practical work session ( P4 , PLO 5 )
PRACTICAL WORK 6 : Array
PRACTICAL WORK DATE :
LECTURER’S NAME:

NAME : TOTAL
STUDENT ID : MARKS
1. Fixes
2. Complete
3. Manipulates
Practical Skill 4. Builds
Assessment 5. Display
[CLO2] 6. Lab Participation
7. Efficiency
Total Practical Skill Assessment
A. Total Practical Skill Assessment (80%) = /35 *80
1. Theory
Report 2. Discussion
Assessment 3. Conclusion
Total Report Assessment
B. Total Report Assessment (20%) = /15*20
Total A+B (100%)
DATE SUBMIT : DATE RETURN :
1 LEARNING OUTCOMES (LO):
1. Understand ARRAY statements.
2. Apply ARRAY statements.
2 OBJECTIVE
1. Define ARRAY statement..
2. Identify the need for ARRAY in programming.
3. Describe the structure of ARRAY..
4. Accessing Array Elements
3 THEORY
1. Definition of ARRAY
2. Declaring an ARRAY
DEFINITION OF ARRAY

Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same
type.

An array is used to store a collection of data, but it is often more useful to think of an array as a collection
of variables of the same type.

Each memory location in array is referred by array’s name and location memory index

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element
and the highest address to the last element.

DECLARING AN ARRAY

To declare an array in C, a programmer specifies the type of the elements and the number of elements
required by an array as follows:

data types arrayName[arraySize];


int Month[10];
This is called single-dimensional array.
arraySize must be integer and >0.

One Dimensional Array


TWO DIMENSIONAL ARRAY

The simplest form of multidimensional array is the two-dimensional array. A two-dimensional array is, in
essence, a list of one-dimensional arrays. To declare a two-dimensional integer array of size [x][y], you
would write something as follows

int Days[3][5];

4 EQUIPMENT / TOOLS
Computer, C programming language ( Dev-cpp, codeblock, dll)
PART A : Independent Learning (NF2F)
(Student must do this task at home or before entering a computer lab)

1. Write the syntax for one dimentional array.

2. Write the syntax for two dimentional array.

3. Write the syntax for three dimentional array.


PART B: Laboratory PW6 (Dependent Learning (F2F)
(To be done in a computer lab)

Practical Assignments 1
Fixes Program 1: The following program contains 5 errors. Students need to verify the error and fix it to
get the correct output.
//Program to calculate average of 4 integers
#include <stdio.h>
int main()
{
int avg = 0;
int sum =0;
int x=0;

int num[4];//array declaration

for (x=0; x<4;x++)


{
printf("Enter number %d \n", x+1);
scanf("%f", &avg[x]);
}
for (x=0, x<4;x++)
{
sum = sum+num[x];
}

avg = sum/6;
printf("Average of entered number is: %d", num);
return 0;
}
Corrected program:
Output:

Practical Assignments 2
Complete Program:

Fill in the blanks to complete this program.

#include<___________ >
int main()
{
int disp[2][3]; //2d declaration
int i, j;
_______(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("Enter value for disp[%d][%d]:", i, j);
scanf("%d", &_________);
}
}
//Displaying array elements
printf("Two Dimensional array elements:\n");
for(i=0; i<2; i++)
{
_______________________
{
printf("______", disp[i][j]);
if(j==2)
{
printf("\n"); //cursor will move to the next row
}
}
}
return 0;
}
Output:

Practical Exercise 1
Manipulates Program 1: Single Dimensional Array
Write a program using array to ask the user to enter the resistor value based on the circuit diagram in
Figure 6.1 below. Calculate the total resistance of the circuit. Build up the flowchart and get the output for
this program. You can modify program in Practical Assignment 1.

Flowchart :
Program:

Output:

Practical Exercise 4
Manipulates Program 2: Multidimensional Array
Write a program to calculate the Power (P) in Circuit 1 and Circuit 2 when the voltage source (V) for the
circuits are varied to 8V, 10V and 12V. The resistor value (R) is fixed to 150Ω and 200Ω.
V V

150Ω 200Ω

Circuit 1 Circuit 2

𝑉
Hint: You need to find current first (𝐼 = ) and your output should looks something like this:
𝑅

Flowchart:
Program:

Output:
Discussion:

Discuss the differences between call by value and call by reference function.
Discuss about types of arrays.

Conclusion:

You might also like