Narc narcissistic number
It is suggested to use three nested loops...
It is suggested to use three nested loops...
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
@echo off
set /a n=100*10000000&set m=0
:begin
if %m% gtr 0 set str=%str%+2*%n%
if %m% gtr 0 set /a str=%str%/10000000
set /a n/=2&set /a m+=1
if %m% lss 10 goto begin
set /a str=%str%+100/2
echo The total distance after the 10th landing of the ball is %str% meters
:lp
if "%n:~,-6%"=="" set n=0%n%
if "%n:~,-6%"=="" goto lp
echo The 10th bounce is 0.%n% meters
pause>nul
@echo off
echo.
echo Three-digit narcissistic numbers are:
echo.
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do (
for /l %%j in (0,1,9) do (
for /l %%k in (0,1,9) do (
set a=%%i
set b=%%j
set c=%%k
set num1=!a!!b!!c!
set /a num2=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !num1! equ !num2! echo !num1!
)
)
)
pause
goto :eof
@echo off
set /a str=6*7*7*7*7*7*4
echo There can be %str% odd numbers formed
pause>nul
Originally posted by terse at 2008-4-11 22:34:
The narcissistic number algorithm is indeed better with three nested loops. The following one I forgot who the moderator wrote, I remember it was written by moderator namejm:
@echo off
echo.
echo Three-digit narcissistic numbers are:
echo.
setlocal ...
@echo off
setlocal enabledelayedexpansion
for /l %%i in (100,1,999) do (
set str=%%i
set/a a=!str:~,1!, b=!str:~1,1!, c=!str:~2,1!
set /a var=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !var! equ !str! echo !str!
)
pause
@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,9) do for /l %%j in (0,1,9) do for /l %%k in (0,1,9) do (
set/a a=%%i,b=%%j,c=%%k
set num1=!a!!b!!c!
set /a num2=!a!*!a!*!a!+!b!*!b!*!b!+!c!*!c!*!c!
if !num1! equ !num2! echo !num1!
)
pause
Originally posted by slore at 2008-4-12 14:45:
Are the number of loops the same?
Which one is less?
Which is faster, taking each digit or combining several digits?
Originally posted by 26933062 at 2008-4-12 03:00 PM:
Find the narcissistic numbers from 1 to 10000, and record the batch processing running time, then you will get the result?