Assignment 2 Solutions.docx - Assignment 2 Solutions \u2013 Spring 2019 Program 1 Cylinder BEGIN MAIN CREATE PI = 3.14 CREATE radius length area volume

# Assignment 2 Solutions.docx - Assignment 2 Solutions u2013...

• Homework Help
• 3

This preview shows page 1 - 3 out of 3 pages.

Assignment 2 Solutions – Spring 2019 Program 1 - Cylinder BEGIN MAIN CREATE PI = 3.14 CREATE radius, length, area, volume radius ← READ user input length ← READ user input area ← radius * radius * PI volume ← area * length PRINTLINE(“Entered radius: “ + radius) PRINTLINE(“Entered length: “ + length) PRINTLINE(“The Volume is “ + volume) END MAIN
Program 2 - SumDigits BEGIN MAIN CREATE inputNum, sum, digit1, digit2, digit3, digit4 inputNum ← READ user input sum inputNum IF (inputNum >= 0 AND inputNum <= 1000) digit1 ← sum % 10 sum ← sum/10 digit2 ← sum % 10 sum ← sum/10 digit3 ← sum % 10 sum ← sum/10 digit4 ← sum % 10 sum ← sum/10 sum ← digit1 + digit2 + digit3 + digit4 PRINTLINE(“Entered number: “ + inputNum) PRINTLINE(“Sum of digits: “ + sum) ELSE PRINTLINE(“Invalid number entered.”) END IF END MAIN
Program 3 - Distance BEGIN MAIN CREATE x1, x2, y1, y2, distance READ user input