CS508 Assignment 01 Fall 2020 Solution / Discussion
CS508 Assignment 01 Fall 2020 Solution / DiscussionProblem Statement:Problem Statement:The following code snippet contains some conditional (nested if else based) statements. Which are difficult to understand as they do not contain any starting or ending keywords against each statement. You, being a programing language expert, are required to put "then" and "end if/else" at appropriate places to get the desired result.Code Snippet:At start, x contains 100 (i.e. x = 100) if (x > 50) x = x * 5 if (x > 500) x = x - 350 if (x > 350) x = x - 150 else x = x + 150 else x = x - 100 if (x > 500) x = x - 150 if (x < 500) x = x + 150 if (x == 500) x = x + 200 else x = x + 100 if (x > 650) x = x - 100 else if (x < 650) x = x + 100 else x = x * 5 else x = x + 50At end, x contains 3250.Note: This is a language-free code, which does not require any specific programming language to compile or execute. You are simply required to guess the flow of execution on the basis of value of x and put "then" and "end if/else" at appropriate places (see the hint given below). Furthermore, you can also add extra lines or spaces in your solution as well.Hint: Difficult to Understand Easily Understandable if (a > b)b = 5elsea = 5 if (a > b) thenb = 5end ifelse thena = 5end else See More
from Latest Activity on Virtual University of Pakistan https://ift.tt/2IZAQ4B
0 comments:
Post a Comment