Assignment 1 Solutions.docx - Assignment 1 Solutions \u2013 Spring 2019 Program 1 BEGIN MAIN CREATE num1 num2 num3 num4 num5 average min max READ user

# Assignment 1 Solutions.docx - Assignment 1 Solutions u2013...

• Homework Help
• 3

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

Assignment 1 Solutions – Spring 2019Program 1BEGIN MAINCREATE num1, num2, num3, num4, num5, average, min, maxREAD user inputnum1 ← first number enterednum2 ← second number enterednum3 ← third number enterednum4 ← fourth number enterednum5 ← fifth number enteredaverage ← (num1 + num2 + num3 + num4 + num5)/5min ←num1if (num2 < min)min ← num2if (num3 < min)min ← num3if (num4 < min)min ← num4if (num5 < min)min ← num5max ←num1if (num2 > max)max ← num2if (num3 > max)max ← num3if (num4 > max)max ← num4if (num5 > max)max ← num5PRINTLINE (“Average of all numbers = “ + average)PRINTLINE(“Maximum Number: “ + max)PRINTLINE(“Minimum Number: “ + min)END MAIN Program 2This one is hardest of the assignment. Using the formula (n(n+1))/2) and a little critical thinking we can find the solution by cutting the stopping point in half and multiplying the whole formula by 2. So, we wind up with 2*(n/2(n/2 + 1))/2 which becomes (n/2)(n/2 + 1) as the division and multiplication by 2 cancel each other.  • • • 