You are on page 1of 13

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: 2 2023/2024

DEC20012: PROGRAMMING FUNDAMENTALS

build programs written in C language for assigned mini


CLO2
project during practical work session ( P4 , PLO 5 )
PRACTICAL WORK : 5 Function And Array

PRACTICAL WORK DATE :

LECTURER’S NAME:

GROUP NO. :

DATE SUBMIT :

PRAC. TOTAL
REPORT
STUDENT ID & NAME : SKILL MARKS
(20%)
(80%) (100%)

(1)

(2)

(3)

REPORT MARK DISTRIBUTION 20%

(1) Result /Output (5)

(2) Discussion (5)

(3) Conclusion (5)

(4) References (5)


Student 1

Student 2
Score 1 2 3 4 5

Score
Aspect Weak Average Satisfactory Good Excellent

Able to write
part of the
Able to write
program
program and Able to write
Write Unable to Able to write correctly but
Program
gives correct program without
write program less than three
output under lecturer’s x6
PRACTICAL SKILL (80%)

program incorrectly quarter of the


supervision of assistance
program under
the lecturer
supervision of
the lecturer
Executing Able to
Unable to Able to execute Execute ALL
program is execute 50%
execute 80% program is program
Execute 30% program is
program
program successfully successfully
successfully successfully x6
with without without
with with
assistance assistance assistance
assistance assistance
Unable to Able to debug Able to debug Able to debug
Debug perform any Able to debug program 50% program 80% ALL program
Program debugging incorrectly correctly with correctly without without x4
program assistance assistance assistance
Able to display Able to display Able to display
Able to display output 50% output 80% all the output
Display
Output output correctly under correctly without excellently
incorrectly x1
incorrectly supervision of the supervision without the help
the lecturer of lecturer of the lecturer
Very
incomplete Some of the All important
Almost of the
or incorrect results have Almost all of the trends and data
results have
interpretatio been correctly results have comparisons
been correctly
n of trends interpreted been correctly have been
interpreted
and and discussed; interpreted and interpreted
Discussion and
comparison partial but discussed, only correctly and
discussed, x1
of data incomplete minor discussed, good
only minor
indicating a understanding improvements understanding of
improvements
REPORT (20%)

lack of of results is are needed results is


are needed
understandi still evident conveyed
ng of results

Accurate
Accurate statement of the
No statement of the results of lab
A statement of
conclusion A statement of results of the lab indicates
the results of
was the results is indicates whether results
the lab
included or incomplete whether results support
Conclusion indicates
shows little with little support the hypothesis
whether x1
effort and reflection on hypothesis Possible
results support
reflection on the lab Possible sources of error
the hypothesis
the lab sources of error and what was
identified learned from the
lab discussed

1-2 3-4
References 0 reference 4-5 references >5 references x1
references references

Total 100
1 LEARNING OUTCOMES (LO):
At the end of this session, student should be able to:
1. Apply Function method in solving problem in C programming.
2. Builds flowchart to solve programming problem before coding.
2 OBJECTIVES
1. Learn how to fix, complete and manipulates the Function method.
2. Learn how to builds flowchart to solve programming problem before coding.
3 THEORY

FUNCTION
A function is a block of statements that performs a specific task. Suppose you are
building an application in C language and in one of your program, you need to perform a
same task more than once. In such case you have two options –
a) Use the same set of statements every time you want to perform the task
b) Create a function to perform that task, and just call it every time you need to
perform that task.

Types of functions

a) Predefined standard library functions – such as puts(), gets(), printf(), scanf() etc
– These are the functions which already have a definition in header files (.h files
like stdio.h), so we just call them whenever there is a need to use them.

b) User Defined functions – The functions that we create in a program are known
as user defined functions.

By user defined function, there are two methods to pass the data into the function in C
language, i.e., call by value and call by reference.

4 EQUIPMENT / TOOLS
Computer, C programming language ( Dev-cpp, codeblock, dll)
Program 1
#include<stdio.h>
void change(int num) // function
{
printf("Before adding value inside function num=%d \
n",num); num=num+100;
printf("After adding operation inside function num=%d \n",num);
}

int main()
{
int x=100;
printf("Before function call x=%d \n", x);
change(x);//calling change() function and passing value x to
it printf("After function call x=%d \n", x);
return 0; }

Built and Run Program 1 using a C compiler


Output: Discuss the output value inside main() and inside function
change()

2. Write the syntax of call by a reference function

Program 2
#include<stdio.h>
void change(int
*num)
{
printf("Before adding value inside function num=%d \
n",*num); (*num) += 100;
printf("After adding value inside function num=%d \n", *num);
}

int main()
{
int x=100;
printf("Before function call x=%d \n", x);
change(&x);//calling change() and passing an reference(address)x to
it printf("After function call x=%d \n", x);
return 0;
}
Built and Run Program 2 using a C compiler
Output: Discuss the output value inside main() and inside function
change()

PART B: Laboratory PW5 (Dependent Learning (F2F)


(To be done in a computer lab)

Practical Assignments 1
Fix the Program:

/* This program objective is to return a sum value of two integer


numbers entered by a user. Unfortunately, it has five errors need to be
mend before it could be use. You are to look for the errors, and fix it
up. */

include <stdio.h>
int addition(int num1, int num2)
{
char sum;

sum = num1+num2;

/* Function return type is integer so we are


returning an integer value, the sum of the num1
and num2. */

return num1;
}

int main()
{
int var1,var2,res;

printf("Enter number 1:
"); scanf("%c",var1);
printf("Enter number 2:
"); scanf("%d",var2);

/* Calling the function here, the function return type


* is integer so we need an integer variable to hold the
* returned value of this function.
*/
res = addition(var1, var2); /*the returned sum value is place in
res variable*/

printf ("Output: %d",

res); return 0;
}
Write the program fixed:

Output :
Practical Assignments 2
Fix the Program:
/* C Program below is supposed to swap values of two integer.
Before it could be used, you need to look up for five errors. Find
out the errors and fix it*/

#include <stdio.h>
void swap(int *, int b); //prototype of the
function int main()
{
int a =
10; int b
= 20;
printf("Before swapping the values in main a = %d, b = %d\
n",a,b);
// printing the value of a and b in
main swap(a,b);
printf("After swapping values in main a = %d, b = %d\n",a,b); //
The values of actual parameters do change in call by reference, a =
10,
b = 20
}
void swap (int *a, int *b)
{
int
temp;
temp =
a;
*a=*b
;
b=tem
p;
printf("After swapping values in function a = %d, b = %d\
n",*a,*b)
; // Formal parameters, a = 20, b = 10
}
Write the program fixed:
Output :

Practical Assignments 3
Complete the Program:
/* The objective of the C program below is to compare two input
numbers and display which one is bigger. It has five blanks that
you should fill up in order to work */

#include<stdio.h> /* function declaration */


/* function returning the max between two numbers */

(int num1, int num2)


{
/* local variable declaration */
result;
if(num1>num2)
result num1;
else
=num
2; return
result;
}

int main ()
{
/* local variable definition
*/ int nom1;
int
nom2;
int
ret;
printf("Input a number :
"); scanf("%d",&nom1);
printf("Input another number :
"); scanf("%d",&nom2);
ret =max(nom1,nom2); /* calling a function to get max value */
printf("Max value is : \n", );
return 0;
}
Write the completed Program :

Output :
Practical Assignments 4
Complete the Program:
/*The c program is used to swap any two integer entered by a user,
It has five blanks that you should fill up in order to work */

#include
void swapnum ( int *var1, int *var2 )
{
int tempnum ;
tempnum = *var1
;
*var1 = ;
*var2 = tempnum ;
}
int main( )
{
int num1, num2;
printf("\n Please enter one integer
number :”); scanf(“ ”,&num1);
printf("\n Please enter another integer
number :”); scanf(“%d”, );

printf("Before swapping:");
printf("\nnum1 value is %d",
num1); printf("\nnum2 value is
%d", num2);

/*calling swap function*/ swapnum( ,__);

printf("\nAfter swapping:");
printf("\nnum1 value is %d",
num1); printf("\nnum2 value is
%d", num2); return 0;
}
Write the completed Program :
Output:
Discussion :

Conclusion:

References:

You might also like