用数组来算大整数的加法
来源:互联网 发布:mac如何把照片拷到u盘 编辑:程序博客网 时间:2024/06/05 04:18
今天我写了一个代码,我同学写了一个代码,都是关于用数组算大整数加法的问题。我们都用了一个数组字符储存四位的方法来算的。
</pre><pre name="code" class="cpp">#include <stdio.h>#include <stdlib.h>#include<ctype.h>#include<string.h>#include<math.h>int main(){ char b[1000],a[1000],c[10]; int d[100],e[100],f[100] ,i, k, len1,len2,sum; gets(a); gets(b); strrev(a); strrev(b); memset(d,0,sizeof(d)); memset(e,0,sizeof(e)); memset(f,0,sizeof(f)); for(i = 0, k= 0; i < strlen(a); i+=4) { c[0] = a[i], c[1] =a[i+1],c[2] = a[i+2],c[3] = a[i+3],c[4] = '\0'; strrev(c); d[k++] = atoi(c); } len1 = k; for(i = 0, k = 0; i < strlen(b); i+=4) { c[0] = a[i], c[1] =a[i+1],c[2] = a[i+2],c[3] = a[i+3],c[4] = '\0'; strrev(c); e[k++] = atoi(c); } len2 = k; for(i = 0, k = 0; i< len1|| i < len2; i++) { sum = log10(d[i] + e[i])+1; if(sum > 4) d[i+1] ++, f[k++] = d[i] + e[i] -10000 , f[k]++; else f[k++] =d[i] + e[i]; } for(i = k-1; i>= 0; i--) printf("%d",f[i]); printf("\n"); return 0;}这是我的代码
0 0
- 用数组来算大整数的加法
- 用数组存储大整数,实现大整数的加法
- 字符数组实现两个大整数的加法
- 整数的加法运算
- 整数的加法拆分
- 大整数的加法
- 大整数的加法
- 大整数的加法
- 使用数组实现大整数加法
- 大整数的加法问题
- 大整数的加法运算
- 用位运算实现两个整数的加法运算
- 使用数组实现过大的非零整数的加法计算(java)
- 整数加法
- 整数加法
- [2017-AspNet-MVC4] 简单加法的演化-1-整数加法
- 有链表实现长整数的加法
- C++的高精度整数加法运算算法
- 程序人生之不要再做个傻傻的程序员
- swift开发之http请求
- UVA Children’s Game(贪心)
- poj 3062
- 【Dokan学习记录】2015-01-30
- 用数组来算大整数的加法
- Windows程序设计第五版 读书体会
- resteasy-spring + springmvc + extdirectspring配置
- Makefile.am、Makefile.in和Makefile的关系
- 1007_素数对猜想 (20)
- Embedded Linux Conference schedule announced, several talks from Free Electrons
- poj 2608 Soundex
- 工作日志
- Android TextView(EditView)文字底部或者中间 加横线