Count in octal: Difference between revisions
Content deleted Content added
→[[Counting in octal#ALGOL 68]]: sample counts only to 17 |
m Alphabetize |
||
Line 2:
The task is to produce a sequential count in octal, starting at zero, and using an increment of a one for each consecutive number. Each number should appear on a single line, and the program should count until terminated, or until the maximum value that can be held within the system registers is reached (for a 32 bit system using unsigned registers, this value is 37777777777 octal).
=={{header|AWK}}==▼
The awk extraction and reporting language uses the underlying C library to provide support for the printf command. This enables us to use that function to output the counter value as octal:▼
<lang awk>BEGIN {▼
for (l = 1; l < 2147483647; l++) {▼
printf("%o\n", l);▼
}▼
}</lang>▼
=={{header|C++}}==▼
This prevents an infinite loop by counting until the counter overflows and produces a 0 again. This could also be done with a for or while loop, but you'd have to print 0 (or the last number) outside the loop.▼
<lang cpp>#include <iostream>▼
#include <iomanip>▼
using namespace std;▼
int main()▼
{▼
unsigned i = 0;▼
do▼
{▼
cout << setbase(8) << i << endl;▼
++i;▼
} while(i != 0);▼
}</lang>▼
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
Line 60 ⟶ 34:
8r00000000021
</pre>
▲=={{header|AWK}}==
▲The awk extraction and reporting language uses the underlying C library to provide support for the printf command. This enables us to use that function to output the counter value as octal:
▲<lang awk>BEGIN {
▲ for (l = 1; l < 2147483647; l++) {
▲ printf("%o\n", l);
▲ }
▲}</lang>
▲=={{header|C++}}==
▲This prevents an infinite loop by counting until the counter overflows and produces a 0 again. This could also be done with a for or while loop, but you'd have to print 0 (or the last number) outside the loop.
▲<lang cpp>#include <iostream>
▲#include <iomanip>
▲using namespace std;
▲int main()
▲{
▲ unsigned i = 0;
▲ do
▲ {
▲ cout << setbase(8) << i << endl;
▲ ++i;
▲ } while(i != 0);
▲}</lang>
=={{header|Fortran}}==
{{works with|Fortran|95 and later}}
|