Inconsummate numbers in base 10: Difference between revisions
Content added Content deleted
(Inconsummate numbers in base 10 in FreeBASIC) |
(Added XPL0 example.) |
||
Line 774: | Line 774: | ||
Ten thousandth 59,853 |
Ten thousandth 59,853 |
||
100 thousandth 536,081 |
100 thousandth 536,081 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">func DigSum(Num); \Return sum of digits of a number in base 10 |
|||
int Num, Sum; |
|||
[Sum:= 0; |
|||
repeat Num:= Num/10; |
|||
Sum:= Sum + rem(0); |
|||
until Num = 0; |
|||
return Sum; |
|||
]; |
|||
func Consum(N); \Return 'true' if N is a consummate number |
|||
int N, M, P; |
|||
[M:= 1; |
|||
repeat P:= M*N; |
|||
if P = N*DigSum(P) then return true; |
|||
M:= M+1; |
|||
until P >= 1000000; \8-) |
|||
return false; |
|||
]; |
|||
int C, N; |
|||
[C:= 0; N:= 1; |
|||
Format(4, 0); |
|||
repeat if not Consum(N) then |
|||
[C:= C+1; |
|||
if C <= 50 then |
|||
[RlOut(0, float(N)); |
|||
if rem(C/10) = 0 then CrLf(0); |
|||
]; |
|||
if C = 1000 then |
|||
[Text(0, "One thousandth inconsummate number: "); |
|||
IntOut(0, N); |
|||
CrLf(0); |
|||
]; |
|||
]; |
|||
N:= N+1; |
|||
until C >= 1000; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
62 63 65 75 84 95 161 173 195 216 |
|||
261 266 272 276 326 371 372 377 381 383 |
|||
386 387 395 411 416 422 426 431 432 438 |
|||
441 443 461 466 471 476 482 483 486 488 |
|||
491 492 493 494 497 498 516 521 522 527 |
|||
One thousandth inconsummate number: 6996 |
|||
</pre> |
</pre> |