You are on page 1of 3

FACULTY OF MECHANICAL ENGINEERING

TEST 1
COURSE : COMPUTER PROGRAMMING

COURSE CODE : BMM1312

LECTURER : UMMU KULTHUM JAMALUDIN

ROSMAZI BIN ROSLI

MOHD AKRAMIN BIN MOHD ROMLAY

FATIMAH BINTI DZAHARUDIN

DATE : 20 OCTOBER 2015

DURATION : 1 HOUR

SESSION/SEMESTER : SESSION 2015/2016 SEMESTER I

PROGRAMME CODE : BMM

INSTRUCTIONS TO CANDIDATE:

1. This examination paper consists of TWO (2) questions. Answer ALL questions.
2. All answers to a new question should start on a new page.
3. All calculations and assumptions must be clearly stated.
4. Candidates are not allowed to bring any material other than those allowed by the
invigilator into the examination room.

EXAMINATION REQUIREMENTS:

1. None

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO

This examination paper consists of THREE (3) printed pages including the front page
CONFIDENTIAL BMM1312I

QUESTION 1 [10 MARKS]

Find all errors in the source code given below, and suggest the correction needed in a table.

Source code:
1 #include (stdio.h)
2 int main()
3 {
4 char first; int second; float third;
5 printf ("Hi there. Please enter a character\n");
6 scanf("%s\n",&first);
7
8 printf ("Please enter an integer\n");
9 scanf("%d",&second);
10
11 printf ("Please enter a floating point number\n");
12 scanf("%f",third);
13
14 printf("you have entered %c, %d and %f \n",first,second,third);
15
16 printf("Thank You\n",first);
17
18 return 0;
19 }
20
21
22

Line Error Correction

2
CONFIDENTIAL BMM1312I

QUESTION 2 [15 Marks]

a) Write a single C program to calculate the following mathematical expressions, f(x,y):

( ) ( )
( )

where x and y are input from the user in radians and M = 0.18. The calculated function
should be in three decimal places and should be displayed on the terminal screen when
the program is executed. (10 Marks)

b) Modify your C program in (a) i.e. use the same mathematical expression, f(x,y) where the
values of M are varied as follow:
if 0 y 0.5
if y > 0.5

Calculate f(x,y) based on the input x and y from the user. The output f(x,y) should be
displayed on the terminal screen in three decimal places as well. (5 Marks)

END OF EXAMINATION PAPER

You might also like