Learn Pascal Programming with Mc Kenzie Program One demonstrated how to instuct Pascal to add two numbers and print the sum. Naturally, Pascal allows programmers to perform all arithmetic operations such as subtract using the - sign, multiply using the asterisk * and divide using the forward slash / . Our second program will perform all four arithmetic operations. Each printing the result of its calculations on a new line. Because of this, four separate writeln statements are used. Two versions are again provided as examples. You are now entering the Pascal World! |
|
Program TwoThis pascal program finds the sum of two numbers 3 and 2 then prints the output 5. Next it calculates the difference between the numbers and prints it. Thirdly the product is calculated and printed. Finally, Pascal divides the first number by the second number and prints the result on the fourth line.
This program also has two parts. 1. The Program Heading 1.0 The Program Heading starts with the word PROGRAM followed by the name of the program. Each program must have a name. The name of this program is Arithmetic. The heading ends with a semi-colon. Here is a second version of the same program :
2.0 The body of the program starts with BEGIN followed by four writeln statements and ends with the word END. Please remember that statements end with the semi-colon but the program ends with a full stop after the word END. The output from the fourth WRITELN statement may not be exactly what you would expect but you will learn to format numeric output in another lesson. BSS Main | Previous Lesson | Next Lesson
|