Sunteți pe pagina 1din 6

EKT 120 Introduction to Computer Programming

Laboratory Module


School of Computer and Communication Engineering

Universiti Malaysia Perlis

EKT 120 Introduction to Computer Programming

Laboratory Module

1.1 Steps to Create New Folder:
1.1.1 Click Places icon > Home Folder > Go to File menu > Create Folder
1.1.2 Rename the New Folder as your Matrix No.
1.2 Steps to Start the Text Editor:
1.2.1 Click Applications icon > Accessories > Text Editor (you are now in
gedit editor).
1.2.2 Once the gedit text editor started, automatically it will view an untitled
1.3 Steps to Create New Program in gedit:
1.3.1 Type the following program:
// Program Example 1
// This program displays message "Welcome to UniMAP
#include <stdio.h>
int main()
printf("\nWelcome to UniMAP\n");
return 0;
1.3.2 Once finished, save the program file or also known as the source file.
1.4 Steps to Save the Source File:
1.4.1 Go to File menu, select Save as option.
1.4.2 Save the file as welcome.c. Type welcome.c in the box besides the
Name location.
if you want to save in a specified folder, select the folder in the save as
dialog box.
(e.g. /home/student/foldername), double click the folder icon and then
type welcome.c in the box besides the Name location. Click Save button.
Notes : The filename must be in one word with extension .c, for
example Program.c or pgm_1.c.
1.5 Steps to Compile a Program:
1.5.1 Click Applications icon > Accessories > Terminal
1.5.2 Use the following commands to check the source file location:
- command to check the current directory
- to list down the files in the current directory.
cd directory - to change directory

If you have found your file, use the command gcc to compile the
program welcome.c
gcc welcome.c

EKT 120 Introduction to Computer Programming

Laboratory Module

Note: after compiling using the above command, if there is no error

a default binary file, a.out is created. This is an executable file.

You can also compile the program and specify the output file (the
executable file) name together with the compile command. This is to
specify or named your binary file related to your program.
gcc -o welcome.out welcome.c
gcc welcome.c -o welcome.out
Note: use the o parameter to specify the output file, followed the
filename that you want to specify.

1.6 Steps to Execute or Run the Program.

1.6.1 In the Terminal window, at the command prompt, run the binary file.

To run the default output (or binary) file, type:


Note: the ./ to specify the binary file is in the current directory.

To run the specific output (or binary) file, type:


When you run the file, the output should be:

Welcome to UniMAP
CONGRATULATIONS!!!! You are now able to write and run your first program

EKT 120 Introduction to Computer Programming

Laboratory Module

Now you have learned to compile a simple C program, try to answer the following
2.1 True or False:

In general, C statement is case sensitive



The name of the primary function of a C program must be main Ans:


main ( ) { } is a complete and correct C program.


2.2 Find error(s), if any, in each statement:


void main (void);


printf (Do we need parentheses here?);


Printf(Is there any wrong here?);


printf(Where do we need a blank space)

2.3 Type, compile and run this program, correct any error(s) you may find and rewrite
the program.

{printf (There is no class tomorrow


2.4 Determine and correct any error(s) you may find in the following command.

in() PRINTF *, (What is wrong?);

EKT 120 Introduction to Computer Programming

Laboratory Module

2.5 Type the following program.

#include <stdio.h>
void main (void)
int dA;
float fB;
dA = 2;
fB = 3.0;
printf(Learning Basic Structure of C Language);
printf(dA + fB = %f, dA+fB);
a. Compile the above program and write down the comment given on the screen
after compiling.

b. Compile the above program to specify the output (binary) to a filename

basic.out and then run the output file. Write the command that you use to
complete the above instruction

c. Write down the output of the program.

d. Format the floating number into 8 numbers and 2 floating point. Write down the
formatting format you use.

e. Correct the program so that the output looks presentable. Describe the changes
you have done and the output of the program.

Write down the changes done to the program:

EKT 120 Introduction to Computer Programming

Laboratory Module

ii. What is the output of the program?


Change the first void to int, then compile the program. Write down any
message after compiling.

g. Explain the program in your own word and describe the command from top until
end of the program.