大整数乘法
来源:互联网 发布:c语言实验报告答案 编辑:程序博客网 时间:2024/05/29 17:48
#include<stdio.h>#include<stdlib.h>#include<string.h>char result[200];void mulStr(char *str, char *one, char* two){ char *str1 = one; char *str2 = two; if(!strcmp(str1,"0")||!strcmp(str2,"0")) { strcpy(str,"0"); return; } bool sinal = true; int len1 = strlen(str1); int len2 = strlen(str2); if(*str1=='-') { len1--; str1++; sinal = !sinal; } if(*str2=='-') { len2--; str2++; sinal = !sinal; } int i,j; int carry=0, out=0,addition; char *result = str; memset(result,'0',len1+len2+1); for(i=len1-1;i>=0;i--) { for(j=len2-1;j>=0;j--) { out = (*(str1+i)-'0')*(*(str2+j)-'0')+carry+*(str+len1+len2-i-j-2)-'0'; *(str+len1+len2-i-j-2) = out%10 + '0'; carry = out/10; } *(str+len1-i+len2-1) = carry +'0'; carry = 0; } char *pend = result + len1 + len2 -1; if(*pend=='0') { if(!sinal) { *pend = '-'; *(pend+1) = 0; pend++; } else { *pend = 0; pend--; } } else { if(!sinal) { *(pend+1) = '-'; *(pend+2) = 0; pend++; } else { *(pend+1)=0; } } char ch; while(result<pend) { ch = *pend; *pend = *result; *result = ch; result++; pend--; } return ;}int main(){ char str1[100]; char str2[100]; char result[200]; while(~scanf("%s %s", str1,str2)) { mulStr(result,str1,str2); printf("%s\n",result); } return 0;}
0 0
- 大整数乘法
- C++大整数乘法
- 大整数FFT乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法。。。。。
- 大整数乘法
- 大整数乘法
- // //大整数乘法
- 大整数乘法
- 大整数乘法算法
- 【算法】 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法。
- 大整数乘法
- Android中Binder通讯机制详解
- ipad/iphone如果快速浏览mac文件
- CVE-2014-0195漏洞分析
- 使用Android Animation注意的地方
- 重写actionbar的up返回按钮
- 大整数乘法
- pscp 的使用
- 使用spring 实现真正多数据源的动态加载及动态切换
- Java基础之理解Annotation
- Base64算法详解和实现【备忘】
- spring 整合JDBC
- WML 是什么
- ccache:利用缓存加速编译过程
- struct cdev结构体以及相关函数