In: Computer Science
What will be the expected output of the following pseudo code? Write exactly what would display when you execute the statements.
Module main() Declare Integer a = 5 Declare Integer b = 2 Declare Integer c = 3 Declare Integer result = 0 Display "The value of result is" Display result Set result = a + b * c - a Display "Changed value is: ", result End Module
output:
The value of result is
0
Changed value is:6
explanation:
a is initialised with 5
b is initialised with 2
c is initialised with 3
and variable result is initialised with 0
display"The value of result is"
this line enclosed in the double quotes will be printed as it is
therfore initial value of result will be 0 and it will be printed
now the result is set to the expression
a + b * c - a
in which a=5,b=2,c=3
accrding to the bodmas rule
multiplication is done first b*c=2*3=6
since operations done from left to right because +,- are having same precision +is done first
5+6=11
now subraction is done
11-5=6
therefore the new value of result will be updated as 6
and the value after display which is enclosed in double quotes will be printed same and this result is appended after the double quotes seperated by comma
this result will be printed after the double quotes enclosed statement
Changed value is: and the updated value of result i.e 6 is printed