高精度加法
来源:互联网 发布:淘宝美工面试被难倒 编辑:程序博客网 时间:2024/06/05 16:32
看完网上教材之后,改动了一些地方,加了一些注释,以便自己理解。特此记录。
附上代码:
#include<stdio.h>#include<string.h>#define MAX 1000int main(void){ char arr1[MAX],arr2[MAX]; memset(arr1,0,sizeof(arr1)); memset(arr2,0,sizeof(arr2)); int len,len1,len2,t,j=0; char str[MAX]; scanf("%s",str); len1=strlen(str); for(int i=0;i<len1;++i) arr1[i]=str[len1-1-i]-'0';/*读入数据,并进行预处理(计算出数字位数,并反方向存放)*/ scanf("%s",str); len2=strlen(str); for(int i=0;i<len2;i++) arr2[i]=str[len2-1-i]-'0'; len=(len1>len2)?len1:len2; for(int i=0;i<len;i++) { t=arr1[i]+arr2[i]+j; arr1[i]=t%10; j=t/10;//看是否进位 } if(j!=0)//如果进位最后一位改变 arr1[len++]=j; for(int i=0;i<len;++i)//输出 printf("%d",arr1[len-1-i]); return 0;}
最后附上原网址
[http://blog.csdn.net/u014253332/article/details/38658215 ] (C语言 高精度算法)
阅读全文
0 0
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度 加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 自定义banner
- EventBus进入Activity页面给Fragment传值,并弹出提示
- hdoj-1280前m大的数
- 插入排序和选择排序
- Mycat——由来
- 高精度加法
- rtrofit @get @path 用注解@get("") 请求数据
- Panel以及Label的设置
- 【技术重温】html之重点(二)
- SpringBoot与Thymeleaf实现国际化
- 带有首尾的可反转链表(LinkedList)的java实现
- Codeforces #339 D. Jon and Orbs(概率dp)
- Div+CSS网页设计(HTML5)
- mybatis中一级缓存和二级缓存的简单介绍