Lab Report 2
Lab Report 2
Lab Report 2
(ECE128)
EXPERIMENT 2
PART A
1. Listing 2-1
INPUT
OUTPUT
2. Listing 2-2
INPUT
OUTPUT
3. Listing 2-3
INPUT
OUTPUT
4. Listing 2-4
INPUT
OUTPUT
PART B
1. Figure 2.2
INPUT
OUTPUT
2. Figure 2.4
INPUT
OUTPUT
EXERCISE
1. INPUT
OUTPUT
2. INPUT
OUTPUT
3. INPUT
OUTPUT
DISCUSSION
For the Exercise part, there are also ‘if’, ‘else’ and ‘switch’ statements. For
the first exercise, the program used ‘if’ and ‘else’ statement. The ‘int’ type is
used as main and were act as value. In this case, ‘if’ statement is used to
determine the value as an even number whereas ‘else’ statement is used to
determine an odd number value. For the second exercise, this program
performs a calculation where rational operator is being asked to be put which
are “+,-,*,/” , so the program can execute a calculation based on the operation
given. In this case, there are ‘int’ type and ‘char’ type where the ‘int’ display the
numbers/values and the ‘char’ is used to put the “arithmetic operation”. ‘if’ and
‘else’ statement are used to execute the operation and display the calculation
based on the “arithmetic operations”. Lastly for the third exercise, this program
is the same as the second exercise but used the ‘switch’ and ‘case’ statement to
write and read easier. In this case, the expression ‘s’ is used in the ‘switch’
statement to act as the “arithmetic operation” whilst the ‘int’ type is use as a
value to perform the calculation which is use in the ‘ans’. Then, ‘default’
statement is used to display the wrong/unknown operation if it does not match
the program.
CONCLUSION
In conclusion, student are able to use the if selection statement and the if…
else selection statement to select actions. Moreover, student is also able to
understand and use the equality and relational operators in the conditional
statements. Lastly, student understand the multiple selection using the switch
selection statement.