如何编写一个程序用数组判断回文数?

来源:百度知道 编辑:UC知道 时间:2024/06/05 07:17:14
用c++语言

pascal语言
program huiweishu;
var
begin
readln(n);
while n<>0 do
begin
i:=i+1;
a[i]:=n mod 10;
n:=n div 10;
end;
f:=true;
for j:=1 to i do if a[j]<>a[i-j+1] then f:=false;
if f=true then writeln('yes') else writeln('no');
end.

data segment
str db '123454321' ;定义一串字符串可以看成是数组形式吧
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bx,offset str
mov di,8
mov si,0
comper: cmp si,di
je stop1
xor ax,ax
mov al,[bx+si]
cmp al,[bx+di]
jne stop2
inc si
dec di
jmp comper
stop1:
mov dl,1h
mov ah,2h
int 21h
jmp endd
stop2:
mov dl,2h
mov ah,2h
int 21h
endd:
mov ah,4ch
int 21h
code ends
end start