Your program needs to print out a header with your name and the lab number (6.9). It will also need 3 column headings, one for the number, one for the next larger number, and one for the difference.
Use the following values when you run your program.
For this program use both a procedure and a function. To the function pass on of the above numbers. This function needs to return the difference to the next number. Use a procedure for printing out the results of each number. These should include the number, the next number, and the delta. Please print all of the numbers in scientific notation. Make sure that you print with enough precision to show the difference between the initial number and the "next" one.
Mark your output with:
The resulting output when the program is run:{ Sample program showing a function call } { Louis Taber 10/14/97 } program func(input,output); { Global variables } var i, j: integer; { Declaration of the function - SumSquare } function SumSquare( ArgOne:integer; ArgTwo:integer): integer; begin SumSquare := ArgOne*ArgOne + ArgTwo*ArgTwo; end; { SumSquare } { Main program - execution starts here } begin { call SumSquare in a loop as part of writeln } writeln(' Function Demo Program '); for i :=3 to 4 do for j := 4 to 5 do writeln(' i =', i:3,' j =', j:3, ' i^2+j^2 = ', SumSquare( i, j):4); writeln; { set a variable to result of SumSquare } i := SumSquare( 23, 56); writeln(' i =', 23:3,' j =', 56:3, ' i^2+j^2 = ', i:4); end.
As an example of a procedure call, global variables, and argument passing here is a program in Pascal:Function Demo Program i = 3 j = 4 i^2+j^2 = 25 i = 3 j = 5 i^2+j^2 = 34 i = 4 j = 4 i^2+j^2 = 32 i = 4 j = 5 i^2+j^2 = 41 i = 23 j = 56 i^2+j^2 = 3665
When the program is run it produces the following output:{ Sample program showing a procedure call } { Louis Taber 10/11/97 } program proc(input,output); { Global variables } var i, j, k: integer; { Declaration of the procedure - variables } procedure variables(var VarArg:integer; j:integer); begin writeln; writeln(' In procedure '); writeln(' i is global and is passed as VarArg'); writeln(' j is a passed value, k is global'); writeln(' VarArg is the local name for '); writeln(' the first passed argument '); writeln(' i= ',i:2,' j= ',j:2, ' k= ',k:2,' VarArg= ',VarArg:2); i := 1; { Change the global variable } j := 1; { Change the local variable } k :=1; { Change the global variable } writeln(' In procedure after i,j, & k are changed'); writeln(' i= ',i:2,' j= ',j:2, ' k= ',k:2,' VarArg= ',VarArg:2); writeln(' Note that VarArg changed! '); VarArg:=4; { Change the passed argument } writeln(' In procedure after VarArg is changed'); writeln(' i= ',i:2,' j= ',j:2, ' k= ',k:2,' VarArg= ',VarArg:2); writeln(' Note that i changed! '); writeln(' i and VarArg are two names for the '); writeln(' same variable location. '); end; { variables } { Main program - execution starts here } begin i := 0; j := 0; k :=0; writeln(' Before procedure '); writeln(' i= ',i:2,' j= ',j:2,' k= ',k:2); { Call procedure variables } { with values i and 8 } { i is called VarArg in procedure } variables( i, 8); { Return from procedure here } writeln; writeln(' After procedure '); writeln(' i= ',i:2,' j= ',j:2,' k= ',k:2); writeln; end.
Before procedure i= 0 j= 0 k= 0 In procedure i is global and is passed as VarArg j is a passed value, k is global VarArg is the local name for the first passed argument i= 0 j= 8 k= 0 VarArg= 0 In procedure after i,j, & k are changed i= 1 j= 1 k= 1 VarArg= 1 Note that VarArg changed! In procedure after VarArg is changed i= 4 j= 1 k= 1 VarArg= 4 Note that i changed! i and VarArg are two names for the same variable location. After procedure i= 4 j= 0 k= 1