We read your photo as:
Write and test a procedure Swap, which takes two integers as parameters and returns the first value passed to the procedure as the second value returned by the procedure and vice versa.
ScanSolve AI Answer
Step-by-step solution
4 stepsHere are the solutions for the programming tasks:
Task 35: Swap
Write and test a procedure Swap, which takes two integers as parameters and returns the first value passed to the procedure as the second value returned by the procedure and vice versa.
Define the
Swapprocedure.The procedure will take two integer parameters by reference, use a temporary variable to hold one value, and then perform the swap.
The
Swapprocedure is defined to exchange the values of two integer variables passed by reference.Task 36: Sort
Write and test a procedureSort, which takes two integers as parameters and returns them in ascending order. For example, ifNo1contained 5 andNo2contained 3, then the callSort(No1, No2)will leave the value 3 inNo1and the value 5 inNo2.Define the
Sortprocedure.The procedure will take two integer parameters by reference. It will compare the two numbers and, if they are not in ascending order, it will call the
Swapprocedure (from Task 35) to reorder them.The
Sortprocedure ensures that the two input numbers are arranged in ascending order.Task 37: Diamond of Stars
Using procedures, write a program that asks the user to enter an odd number, validates the number, and then displays a diamond of stars based on that number. For example, the value 7 would produce:* *** ***** ******* ***** *** *Define the
PrintDiamondprocedure.This procedure will take the odd number
Nas input and print the diamond pattern.Write the main program to get input, validate, and call the procedure.
The program prompts the user for an odd number, validates the input, and then uses the
PrintDiamondprocedure to display the star pattern.
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.