You are on page 1of 4

UNIVERSITI TUN HUSSEIN ONN MALAYSIA

FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING


COMPUTER PROGRAMMING (BDA 24202)

LAB SHEET 2
Computer Programming Basics

NG:YING KHIAN
NAME
_________________________________

(MARKS)
130220
MATRICS NO.:AD
_______________
_________

DATE
:
9/3/2015

Objectives:
Learn to write pseudo code
Learn to draw flow chart

NG YING KHIAN AD130220 (SEKSYEN 2)

UNIVERSITI TUN HUSSEIN ONN MALAYSIA


FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING
COMPUTER PROGRAMMING (BDA 24202)

Question 1
a) The purpose of the program is to print Welcoming text on screen when the program is
run.
Variablesdo not have any variables in this program
Inputdo not required any input for this program
Outputdisplay a welcome text on screen by preprocessor directives printf (_____)
; Punctuation
\n new line
b) /* The purpose of the program is to print text on screen when run.*/
#define MESSAGE Welcome to this computer programming class!\n
main( )
Predefine

printf(MESSAGE);
}

Ne
w
line

Output

c) main( )
{

float gross, tax, net;

\\ Declarations of Variables

\\ Statements
printf(Gross salary: );
scanf(%f, &gross);
\\ Input
tax = 0.14*gross;
net = gross tax;
printf(Taxes withheld: %.2f\n, tax); \\Output

NG YING KHIAN AD130220 (SEKSYEN 2)

UNIVERSITI TUN HUSSEIN ONN MALAYSIA


FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING
COMPUTER PROGRAMMING (BDA 24202)

Question 2
i) Flow chart

ii) Pseudo code


1. Start

Start

2. Display How do you go


lecture from your house?

Set
a= Bus
b= own transport
c= by walking

a= Bus
b= own transport
c= by walking
3. Input a or b or c
4. Print output
5. Ends

If a

If b

Display
By bus

Display
Own Transport

If c then Display
By walking

End

NG YING KHIAN AD130220 (SEKSYEN 2)

UNIVERSITI TUN HUSSEIN ONN MALAYSIA


FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING
COMPUTER PROGRAMMING (BDA 24202)

Question 3

Start

Enter a value for the principal (p)

Enter value for the interest rate (r)

Enter value for the num. of years (n)

Calculate i=r/100
f= p*pow((1+i),n)

Display final value f=_____

End

NG YING KHIAN AD130220 (SEKSYEN 2)

You might also like