#include
int main()
{
char deno[1000]={'\0'},num,i=0,remain=0;
scanf("%s %d",deno,&num); //獲取被除數、除數
if(!num) return (-1);
while(deno[i]!='\0')
deno[i++]-='0'; //轉換成數字
deno[i]='#'; //結束標志
i=0;
while(deno[i]!='#')
{
deno[i]+=remain; //低位+高位余數
remain=10*(deno[i]%num); //高位余數
deno[i]=deno[i]/num+'0'; //商的ASCII碼
i++;
}
deno[i]='\0'; //串尾
remain/=10; //最後余數
if(deno[0]=='0'&&deno[1]!='\0') //高位0不顯示
printf("%s %d",&deno[1],remain);
else
printf("%s %d",deno,remain);
return 0;
}
VC++6.0下運行結果:
GCC編譯後運行結果:
(gdb) n
12 4
Breakpoint 1, main (argc=1, argv=0x7fffffffe288) at source.c:7
7 if(!num) return (-1);
(gdb) p deno
$1 = '\000'
(gdb) p deno[0]
$2 = 0 '\000'
(gdb)