Documente Academic
Documente Profesional
Documente Cultură
NAME
IC NO
SECTION
LECTURER
1
SECTION A – TRUE/FALSE QUESTIONS [10 MARKS]
ANSWER ALL (10) QUESTIONS.
(True/
Questions
False)
1. Programming is a procedure for solving a problem in terms of the actions and
the order are to be executed
1. Loop specifies a block of one or more statements that are repeatedly executed
3.
until a condition is satisfied
5. Comments cause the computer to display the text after // on the screen when
the program is executed.
6. All arguments following the format control string in a printf function must be
preceded by an ampersand (&).
7. A program that prints three lines of output must contain three printf
statements.
2
SECTION B – STRUCTURE QUESTIONS [55 MARKS]
ANSWER ALL (8) QUESTIONS.
1. Write a pseudocode representing the problem of finding the total (SUM) of the first 50
numbers (N).
2. Draw a flowchart for above problem.
3
Question 2 (11 marks)
Flowchart in figure below is to find the smallest and largest values for 10 scores. Fill in the
blank (a, b, c, d, and e) graphical symbols with appropriate instructions.
a) _________________
b) _________________
c) _________________
d) _________________
e) _________________
Trace the flowchart above and display the output, if the input is 23, 15, 31, 27, 34, 16, 7, 28,
49 and 11. Complete the table below.
No. Read, n S L C
Output : ____________________________
4
Question 3 (4 marks)
Which of the following identifier is Valid/Not Valid? Give your justification if the identifier
is not valid.
Question 4 (5 marks)
Write a complete C program to calculate TOTAL and AVERAGE for the four integers.
a) State or describe that a program will calculate the sum and average of 4 integers.
b) Define the variables a, b, c and d be a type of integer and TOTAL and AVERAGE as
type of floating point.
d) Read four integer from the keyboard and store them in the variables a, b, c and d.
e) Compute and display the TOTAL and AVERAGE of four integers contained in variables a,
b, c and d.
5
Question 5 (6 marks)
b) =
Question 6 (6 marks)
Solve the statements and show your steps in the table below.
Question 7 (7 marks)
b) Read 3 values (type integer, float, character) into variable A, B and C in one statement.
6
What does each of the following statements print?
Assume int i=1, j=2, k=3, m=2
d) printf("%d\n", j==3);
e) printf("%d\n", i>=1 && j<4);
f) printf("%d\n",j>=i || k==m);
g) printf("%d\n",!(j-m));
Question 8 (6 marks)
int a = 6;
int b = a--; Output
printf("%d\n", a);
printf("%d\n", b);
a = 6;
b = --a;
printf("%d\n", a);
printf("%d\n", b);
a = 10; b = 12;
a = ++a + b--;
b-=7;
printf("%d\n", a);
printf("%d\n", b);
7
SECTION C: PROGRAMMING QUESTIONS [35 MARKS]
ANSWER ALL (2) QUESTIONS.
Medium Speed
Air 335.3 meter per second
Water 1493.5 meter per second
Steel 4998.7 meter per second
Write a program that displays a menu allowing the user to select air, water or steel. After the
user has made a selection, he/she should be asked to enter the distance a sound wave will
travel in the selected medium. The program will then display the amount of time take.
(Round the answer to four decimal places)
Input validation: Check that the user has selected one of the available choices from the menu.
Do not accept distances less than 0.
ANSWER :
8
Question 2 (25 MARKS)
A bank charges RM20 per month plus the following check fees for a commercial checking
account:
The bank also charges an extra RM25 if the balance of the account falls below RM500
(before any check fee are applied). Draw a flowchart and write a program that asks for the
beginning balance and the number of checks written. Compute and display the bank’s service
fees for the month.
Input validation: Do not accept a negative value for the number of checks written. If a
negative value is given for the beginning balance, display an urgent message indicating the
account is overdrawn.