Difference between revisions of "Basic Pascal Tutorial/Chapter 1/Solution"

From Lazarus wiki
Jump to navigationJump to search
(Use pascal highlighter)
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{ Solution }}
 +
{{TYNavigator|Programming_Assignment|Input}}
 +
 
1Ha - Solution (author: Tao Yue, state: unchanged)
 
1Ha - Solution (author: Tao Yue, state: unchanged)
  
 
Here's one way to solve the programming assignment in the previous section.
 
Here's one way to solve the programming assignment in the previous section.
<delphi>
+
<syntaxhighlight lang=pascal>
 
(* Author:    Tao Yue
 
(* Author:    Tao Yue
 
   Date:      19 June 1997
 
   Date:      19 June 1997
Line 38: Line 41:
 
   writeln ('Average = ', Average)
 
   writeln ('Average = ', Average)
 
end.    (* Main *)  
 
end.    (* Main *)  
</delphi>
+
</syntaxhighlight>
  
{|style=color-backgroud="white" cellspacing="20"
+
{{TYNavigator|Programming_Assignment|Input}}
|[[Programming_Assignment|previous]] 
 
|[[Contents|contents]]
 
|[[Input|next]]
 
|}
 

Revision as of 19:07, 16 January 2020

български (bg) Deutsch (de) English (en) français (fr) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

 ◄   ▲   ► 

1Ha - Solution (author: Tao Yue, state: unchanged)

Here's one way to solve the programming assignment in the previous section.

(* Author:    Tao Yue
   Date:      19 June 1997
   Description:
      Find the sum and average of five predefined numbers
   Version:
      1.0 - original version
*)

program SumAverage;

const
   NumberOfIntegers = 5;

var
   A, B, C, D, E : integer;
   Sum : integer;
   Average : real;

begin    (* Main *)
   A := 45;
   B := 7;
   C := 68;
   D := 2;
   E := 34;
   Sum := A + B + C + D + E;
   Average := Sum / NumberOfIntegers;
   writeln ('Number of integers = ', NumberOfIntegers);
   writeln ('Number1 = ', A);
   writeln ('Number2 = ', B);
   writeln ('Number3 = ', C);
   writeln ('Number4 = ', D);
   writeln ('Number5 = ', E);
   writeln ('Sum = ', Sum);
   writeln ('Average = ', Average)
end.     (* Main *)
 ◄   ▲   ►