大数乘法
#include <iostream> ? } ? char *tmp=(char*)malloc(sizeof(char)*(length_a+length_b+1));//必须加1,否则数组会溢出报错,因为是字符数组最后一位还要补 ? strcpy(tmp,"0"); ? t=0; ? while(s[t]==0)t++;//跳过高位的0,即数组头部的0 ? for(k=0;t<length_a+length_b;t++) ? { ?? tmp[k++]=s[t]+'0'; ? } ? tmp[k]=' '; ? cout<<"a b两个数相乘所得的结果为:"<<endl; ? cout<<tmp<<endl; ? free(s);//创建的s数组空间一定要释放,否则会有内存泄露的危险 ? free(tmp); } void main() { ?string a,b; ?cout<<"请输入a b两个大数:n"; ??? cin>>a>>b; ?const char *ach,*bch; ?ach=a.c_str(); ?bch=b.c_str(); ??? multiply_by_big_data(ach,bch); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |