Exercise - goestinov

Download Report

Transcript Exercise - goestinov

Subject : T0016 – ALGORITHM AND PROGRAMMING
Year
: 2013
Review Materials I (T)
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
T0016 - Algorithm and
Programming
3
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.
T0016 - Algorithm and
Programming
4
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” ?
T0016 - Algorithm and
Programming
5
Exercise
4. If all variables are integer, then state the value of A if:
B=13;
a) A
b) A
c) A
d) A
e) A
f) A
g) A
h) A
i) A
j) A
C=11; D=42; E=0;
= B && E;
= B & C;
= C || D;
= B | D;
= B > 2;
= B >> 2;
= C < 3;
= C << 3;
= B = C;
= B == C;
T0016 - Algorithm and
Programming
6
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)
grade = 'A';
if(mark>=75)
grade = 'B';
if(mark>=85)
grade = 'A'
else if(mark>=75)
grade = 'B‘
(a)
(b)
If mark is 90, what is the output of grade from (a) and (b)?
T0016 - Algorithm and
Programming
7
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?
T0016 - Algorithm and
Programming
8
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
T0016 - Algorithm and
Programming
9
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!
T0016 - Algorithm and
Programming
10
END
T0016 - Algorithm and
Programming
11