我直接写出最重要的把,只写子程序好了。
3:
procedure f(x,s:longint);
begin
if x=0 then begin writeln(s);exit;end;
f(x div 10,s*10+x mod 10);
end;
主程序中: f(x,0);(x是要颠倒的数);
6:
procedure f(x,s,t:longint);
begin
if t=0 then begin writeln(s);exit;end;(我直接用颠倒数字,为了防止最后的零不输出,我就设定了位数)
f(x div 10,s*10+x mod 10,t-1);
end;
procedure f1(x,s:longint);
var
t:longint;
begin
if x=0 then begin f(s,0,t);end;
t:=t+1;
f(x div m,s*10+(x mod m));
end;
主程序中:readln(m);(进制);f1(x,0);(x是要换进制的数);
如果用数组的话可以更好一点,我这样直接
#include "stdio.h"
void print(int x)
{
printf("%d",x%10);
if(x>=10)
print(x/10);
}
void main()
{
int n;
scanf("%d",&n);
print(n);
printf("\n");
}
#include
void print(int x)
{
printf("%d",x%10);
if(x>=10)
print(x/10);
}
int main()
{
int n;
scanf("%d",&n);
print(n);
printf("\n");
}