Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

Subject : COMP6047

ALGORITHM AND PROGRAMMING


Year : 2019

Review Materials I
Review Materials
• Algorithm & Programming
• Introduction to C Programming I
• Introduction to C Programming II
• Operator, Operand, and Arithmetic
• Program Control: Selection
• Program Control: Repetition
• Pointers and Arrays

COMP6047 - Algorithm and Programming 2


Exercise
1. Create Pseudocode and Flowchart for the following problem :

A shopping market is in need of a program to support cashier.


The program will first read the product code from screen, validate
that product code should be 10 digits of characters. Other than
that, quantity and price will be asked for each of products.
Program will also need to validate if quantity and price is all
numbers with minimum value of 1. All these process will be
repeated for every products shopped by customer.
Program will stop computing and display the amount that
should be paid by customer when user input product code with
0000000000.

COMP6047 - Algorithm and Programming 3


Exercise
2. Decide if the following statements are TRUE or FALSE
a) Variable name can be started with numbers, ex : 1name
b) Variable name can not consist of more than a word
c) We can make variable with name of : system

3. Do the following syntax : scanf(“%s”, temp) and gets(temp)


have the same function? What is the output if the input is :
“Good Morning” ?

COMP6047 - Algorithm and Programming 4


Exercise
4. If all variables are integer, then state the value of A if:
B=13; C=11; D=42; E=0;
a) A = B && E;
b) A = B & C;
c) A = C || D;
d) A = B | D;
e) A = B > 2;
f) A = B >> 2;
g) A = C < 3;
h) A = C << 3;
i) A = B = C;
j) A = B == C;

COMP6047 - Algorithm and Programming 5


Exercise
5. Given the following decimal : 15870, convert it to :
a) Binary
b) Octal
c) Hexadecimal
6. What is the result of z = (x ==1) ? 5 : 7 if x is 0 ?
7. Are these two block of codes the same?
if(mark>=85) if(mark>=85)
grade = 'A'; grade = 'A'
if(mark>=75) else if(mark>=75)
grade = 'B'; grade = 'B‘

(a) (b)
If mark is 90, what is the output of grade from (a) and (b)?

COMP6047 - Algorithm and Programming 6


Exercise
8. What is Nested if?
9. What is the main difference between do-while statements and
while statements in C?
10. Create the following program : N = 10

11. How do we validate length of a string is no more than 30 and


not less than 5?

COMP6047 - Algorithm and Programming 7


Exercise
12. Create a program to convert all first letters of every word to be
uppercase, while the rest is remain unchanged
Example :
– happy Birthday  Happy Birthday
– Good MorNinG  Good MorNinG
– good night  Good Night

COMP6047 - Algorithm and Programming 8


Exercise
13. Create a program to check if a word is palindrome!
example : exe, madam, mam, mom, dad
14. Create a program to do multiplication of these two matrices,
using array 2D!

COMP6047 - Algorithm and Programming 9


END

COMP6047 - Algorithm and Programming 10

You might also like