Professional Documents
Culture Documents
Input/Output Processing
Start/Stop
Decision
Program Heading
Program Declaration
Program Block
Program Terminator (a period)
program add; Heading
{This program finds the sum of two numbers}
VAR
num1,num2:integer; Declaration
sum:integer;
BEGIN
writeln('Enter the first number');
readln(num1);
writeln('Enter the second number'); Body
readln(num2);
sum:=num1+num2;
Writeln('The sum of the two numbers is ',sum);
END.
Terminator
Program LargestNumber;
{This program finds the largest of 3 numbers}
VAR
num1, num2, num3:integer;
largest:integer;
BEGIN
Writeln('Enter the first number');
Readln(num1);
Writeln('Enter the second number');
Readln(num2);
Writeln('Enter the third number');
Readln(num3);
If num1>num2 then
largest:=num1
else
largest:=num2;
If largest<num3 then
largest:=num3;
Writeln('The largest number is ',largest);
END.
Program average;
{This program finds the average of three numbers}
VAR
num1,num2,num3:integer;
average:real;
BEGIN
writeln('Enter the first number');
readln(num1);
writeln('Enter the second number');
readln(num2);
writeln('Enter the third number');
readln(num3);
average:=(num1+num2+num3)/3;
Writeln('The average of the three numbers is ',average);
END.
Program StudAverageScores;
{This program find the average of 5 students scores}
Var
i:integer;
Score:integer;
AvgScore:real;
TotScore:integer;
BEGIN
Score:=0;
TotScore:=0;
AvgScore:=0;
For i:=1 to 5 do
begin
Writeln('Enter the student # ' , i, ' score');
Readln(Score);
TotScore:=TotScore+Score;
end; {end for}
AvgScore:=TotScore/5;
writeln;
Writeln('The average score is ',round(AvgScore));
End.
Program StopWhenISee_0;
{This program accepts a value of 'a' until 0 is entered}
var
x,a:integer;
BEGIN
Writeln('Enter a value for a');
Readln(a);
While a<>0 do
begin
x:=a+5;
Writeln('The value of x is ',x);
writeln;
writeln;
Writeln('Enter a value for a');
Readln(a);
End; {endwhile}
END.