Practical Work 6 Labsheet
Practical Work 6 Labsheet
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:
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)
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;
avg = sum/6;
printf("Average of entered number is: %d", num);
return 0;
}
Corrected program:
Output:
Practical Assignments 2
Complete 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: