Logic7e_Solutions_ch05 - Programming Logic and Design 7e...

This preview shows page 1 - 9 out of 40 pages.

Programming Logic and Design, 7eSolutions 5-1Programming Logic and Design, 7th EditionChapter 5Exercises1.What is output by each of the pseudocode segments in Figure 5-22?Answer: a.5, 22, 5b.4, 6, 7c.6, 6
2.Design the logic for a program that outputs every number from 1 through 20.
Programming Logic and Design, 7eSolutions 5-2Pseudocode:startDeclarationsnum numberhousekeeping()while number <= 20detailLoop()endwhilefinishUp()stophousekeeping()number = 1returndetailLoop()output numbernumber = number + 1returnfinishUp()output “End of program”return
Programming Logic and Design, 7eSolutions 5-33.Design the logic for a program that outputs every number from 1 through 20 along with its value doubled and tripled.Answer: A sample solution followsFlowchart:Pseudocode:startDeclarationsnum numbernum doublenum triplehousekeeping()while number <= 20detailLoop()endwhilefinishUp()stophousekeeping()
Programming Logic and Design, 7e
4.Design the logic for a program that outputs every even number from 2 through 100.
Programming Logic and Design, 7eSolutions 5-5Pseudocode:startDeclarationsnum numberhousekeeping()while number <= 100detailLoop()endwhilefinishUp()stophousekeeping()number = 2returndetailLoop()output numbernumber = number + 2returnfinishUp()output “End of program”return5.Design the logic for a program that outputs numbers in reverse order from 25 down to 0.
Programming Logic and Design, 7eSolutions 5-6Pseudocode:startDeclarationsnum numberhousekeeping()while number >= 0detailLoop()endwhilefinishUp()stophousekeeping()number = 25returndetailLoop()output numbernumber = number - 1returnfinishUp()output “End of program”
Programming Logic and Design, 7eSolutions 5-7return6.Design the logic for a program that allows the user to enter a number. Display the sum of every number from 1 through the entered number.
Programming Logic and Design, 7eSolutions 5-8num addNumhousekeeping()while addNum <= numberdetailLoop()endwhilefinishUp()stophousekeeping()output “Enter a number >> ”input numberaddNum = 1returndetailLoop()output (addNum + number)addNum = addNum + 1returnfinishUp()output “End of program”return

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture