Thứ Hai, 3 tháng 12, 2012

Số Amstrong- Kim Ngân

program so_amstrong;
uses crt;
var i, so, p, j, b, h,  bx:integer;
    s:string;
begin
     clrscr;
     write('nhap day so bat ki: ');readln(so);
     p:=0; str(so,s); h:=so;
         repeat
               b:=so mod 10; so:=so div 10;
               bx:=b;
               for j:=2 to length(s) do
                   bx:=bx*b;
               p:=p+bx;
         until so=0;
         if p=h then writeln(h,'la so amstrong');
     readln;
end.

Không có nhận xét nào:

Đăng nhận xét