CS508 Assignment No1 solution 2023 By MAS All Rounder

MAS All Rounder
0

For More Assignments & GDBs Solution

 Visit: masallrounder.blogspot.com

CS508 Assignment No1 solution 2023

The following code snippet contains some conditional (nested if else /else if based) statements. Which are difficult to understand as they do not contain any starting or ending keywords against each statement. You, being a programming language expert, are required to put "then" and "end if/else/else if" 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 > 200){  

 x = x - 200;  

 }if (x > 350){  

 x = x - 150;  

 }else{  

 x = x + 150;  

 }  

 if (x > 400){  

 x = x - 150;  

 }if (x < 500){  

 x = x + 150;  

 }if (x == 500){  

 x = x + 200;  

 }else if (x > 400){  

 x = x - 100;  

 }else if (x < 650){  

 x = x + 100;  

 }else{  

 x = x * 5;  

 }  

At end, x contains 350.  

Solution:  

At start, x contains 100 (i.e. x = 100)  

if (x > 50){ then 

 x = x * 5;  

end if  

}  

if (x > 200){ then

 x = x - 200;  end if  

}  

if (x > 350){ then  x = x - 150;  end if  

}else { then 

 x = x + 150;  end else  

}  

if (x > 400){ then  x = x - 150;  end if  

}  

if (x < 500){ then  x = x + 150;  end if  

}  

if (x == 500){ then  x = x + 200;  end if  

}  

else if (x > 400){ then   x = x - 100;  end else if  

}  

else if (x < 650){ then   x = x + 100;  end else if  

}  

else { then 

 x = x * 5;  

end else  

 

For More Assignments & GDBs Solution

 Visit: masallrounder.blogspot.com



 DOWNLOAD NOW

 


Post a Comment

0Comments

Post a Comment (0)