再次修改代码~大位数乘法~
看看这个能不能改好?~先谢过了~程序代码:
#include<stdio.h> #include<string.h> #define N 101 void Init(char a[]); char* fun(char a[],char b[],char c[]); int main() { char a[N+1]={0}; //默认A比B长 char b[N+1]={0}; char c[N+2]={0}; Init(a); Init(b); printf("%s\n",fun(a,b,c)); return 0; } void Init(char a[]) { char c=0; int i=1; a[0]='0'; while ((c=getchar())!='\n') a[i++]=c; } char* fun(char a[],char b[],char c[]) { char* pa=a+strlen(a)-1; //*pc+=((*pa-'0')+(*pb-'0')) char* pb=b+strlen(b)-1; char* pc=c+N-2; int s=0; while(pb!=b) { char* pa=a+strlen(a)-1; int jin=0; while(pa!=a) { if((*pa-'0')*(*pb-'0')>=10) { *pc=*pc+((*pa-'0')*(*pb-'0')+jin)%10; //进位与入数组 jin=((*pa-'0')*(*pb-'0'))/10; } else if(((*pa-'0')*(*pb-'0'))<10) { *pc=*pc+((*pa-'0')*(*pb-'0'))+jin; } if((*pc-'0')>=10) { *(pc-1)+=1; *pc=(*pc-'0')%10; } --pa; --pc; } s++; --pb; pc=c+N-2-s; } return (pc+s+strlen(c)-1); }