Basic Pascal Tutorial/Chapter 1/Programming Assignment
Sent here from Programming Assignment.
한국어 · Deutsch · English · Français · Български · Русский · 中文(中国) · 日本語
1H - Programming Assignment (author: Tao Yue, state: changed)
Now you know how to use variables and change their value. Ready for your first programming assignment?
But there's one small problem: you haven't yet learned how to display data to the screen! How are you going to know whether or not the program works if all that information is still stored in memory and not displayed on the screen?
So, to get you started, here's a snippet from the next few lessons. To display data, use:
writeln (argument_list);The argument list is composed of either strings or variable names separated by commas. An example is:
writeln ('Sum = ', sum);Here's the programming assignment for Chapter 1:
Find the sum and average of five integers. The sum should be an integer, and the average should be real. The five numbers are: 45, 7, 68, 2, and 34.
Use a constant to signify the number of integers handled by the program, i.e. define a constant as having the value 5.
Then print it all out! The output should look something like this:
Number of integers = 5
Number 1 = 45
Number 2 = 7
Number 3 = 68
Number 4 = 2
Number 5 = 34
Sum = 156
Average = 3.1200000000E+01As you can see, the default output method for real numbers is scientific notation. Chapter 2 will explain you how to format it to fixed-point decimal.
To see one possible solution of the assignment, go to the next page.
From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Programming Assignment", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Edited on wiki.freepascal.org by 8 people, 2007–2022
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Kees | New page: 1H - Programming Assignment Now you know how to use variables and change their value. Ready for your first programming assignment? But there's one small problem: you haven't yet learned ... | |
| Kees | ||
| Kees | ||
| Kees | ||
| Vincent | Text replace - "delphi>" to "syntaxhighlight>" (minor) | |
| Jwdietrich | ||
| Ihkim | ||
| FTurtle | ||
| FTurtle | ||
| Trev | Fixed syntax highlighting (minor) | |
| Kai Burghardt | Kai Burghardt moved page Programming Assignment to Basic Pascal Tutorial/Chapter 1/Programming Assignment: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: Perm... (minor) | |
| Gnofs | Readability (minor) | |
| Kai Burghardt | bypass redirects [cf. discussion] | |
| Kai Burghardt | bypass language bar/categorization template redirect [cf. discussion] (minor) |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
