Square but not cube: Difference between revisions

Add MACRO-11
(Add 8080 Assembly)
(Add MACRO-11)
 
(2 intermediate revisions by the same user not shown)
Line 198:
 
<pre>4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089 </pre>
 
=={{header|ABC}}==
<syntaxhighlight lang="abc">PUT 1 IN square.root
PUT 1 IN cube.root
PUT 30 IN amount
 
WHILE amount > 0:
WHILE square.root ** 2 > cube.root ** 3:
PUT cube.root + 1 IN cube.root
IF square.root ** 2 <> cube.root ** 3:
WRITE square.root ** 2/
PUT amount - 1 IN amount
PUT square.root + 1 IN square.root</syntaxhighlight>
{{out}}
<pre>4
9
16
25
36
49
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
784
841
900
961
1024
1089</pre>
 
=={{header|Action!}}==
Line 2,310 ⟶ 2,354:
676
729 is square and cube
784
841
900
961
1024
1089</pre>
 
=={{header|MACRO-11}}==
<syntaxhighlight lang="asm"> .TITLE SQRCUB
.MCALL .TTYOUT,.EXIT
 
SQRCUB::MOV #^D30,R5
JSR PC,NEXCUB
1$: JSR PC,NEXSQR
2$: CMP R4,R3
BLT 3$
BEQ 1$
MOV R3,R0
JSR PC,PR0
SOB R5,1$
.EXIT
3$: JSR PC,NEXCUB
BR 2$
 
; PUT SUCCESSIVE SQUARES IN R3
NEXSQR: MOV 1$,R3
ADD 2$,R3
MOV R3,1$
ADD #2,2$
RTS PC
1$: .WORD 0
2$: .WORD 1
 
; PUT SUCCESSIVE CUBES IN R4
NEXCUB: CLR R4
MOV 3$,R1
1$: ADD 2$,R4
ADD #2,2$
SOB R1,1$
INC 3$
RTS PC
2$: .WORD 1
3$: .WORD 1
 
; PRINT R0 AS DECIMAL WITH NEWLINE
PR0: MOV #4$,R2
1$: MOV #-1,R1
2$: INC R1
SUB #12,R0
BCC 2$
ADD #72,R0
MOVB R0,-(R2)
MOV R1,R0
BNE 1$
3$: MOVB (R2)+,R0
.TTYOUT
BNE 3$
RTS PC
.BLKB 5
4$: .BYTE 15,12,0
.END SQRCUB</syntaxhighlight>
{{out}}
<pre>4
9
16
25
36
49
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
784
841
Line 3,094 ⟶ 3,224:
1 64 729 4096 15625 46656 117649 262144 531441 1000000 1771561 2985984 4826809 7529536 11390625</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <SquareCube 30>>;
};
 
SquareCube {
s.Max = <SquareCube s.Max 1 1>;
0 s.Sqrt s.Cbrt = ;
 
s.Max s.Sqrt s.Cbrt,
<Square s.Sqrt>: s.Square,
<Cube s.Cbrt>: s.Cube,
<Compare s.Square s.Cube>: {
'-' = s.Square
<SquareCube <- s.Max 1> <+ 1 s.Sqrt> s.Cbrt>;
'0' = <SquareCube s.Max <+ 1 s.Sqrt> s.Cbrt>;
'+' = <SquareCube s.Max s.Sqrt <+ 1 s.Cbrt>>;
};
};
 
Square { s.N = <* s.N s.N>; };
Cube { s.N = <* s.N <* s.N s.N>>; };</syntaxhighlight>
{{out}}
<pre>4 9 16 25 36 49 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 784 841 900 961 1024 1089</pre>
=={{header|REXX}}==
Programming note: &nbsp; extra code was added to support an additional output format &nbsp; (see the 2<sup>nd</sup> '''output''' section).
2,094

edits