C-高精度除法
来源:互联网 发布:淘宝1111购物狂欢节 编辑:程序博客网 时间:2024/06/06 15:02
直接贴喽
#include<stdio.h>
#include<string.h>
intlen1,len2;
chars1[905],s2[905];
intre[905];
voidsub()
{
int i=0,j;
while(1)
{
if(s1[i]=='0') i++;
else
{
j=i;
break;
}
}
for(;i<len2;i++)
s1[i]=s1[i]-s2[i]+'0';
for(i=len2-1;i>j;i--) //低位开始检测是否小于0
if(s1[i]<'0')
{
s1[i]+=10;
s1[i-1]--;
}
}
intmain()
{
int i,p;
scanf("%s%s",s1,s2);
len1=strlen(s1);
len2=strlen(s2);
if(len1<len2 || (len1==len2 &&strncmp(s1,s2,len2)<0)) //如果a<b,直接输出0
printf("0\n");
p=0;
while(1)
{
re[p]=0;
while(strncmp(s1,s2,len2)>=0) //一直进行减法,直到不能减为止
{
sub();
re[p]++;
}
p++;
if(len1==len2) break;
for(i=len2-1;i>=0;i--) //在s2前面补0,以便进行减法运算
s2[i+1]=s2[i];
s2[0]='0';
len2++;
s2[len2]='\0';
}
i=0;
while(1)
{
if(re[i]==0) i++;
else break;
}
for(;i<p;i++)
printf("%d",re[i]);
return 0;
}
- 【C++】高精度除法
- C语言 高精度除法
- C-高精度除法
- (C语言)高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 高精度除法
- 获取指定路径下所有文件生成树型结构列表
- Linux相关网址收藏
- java开发系统内核:cls 屏幕清空命令的实现
- 如何理解css的BFC抽象概念
- c#中ref与out区别
- C-高精度除法
- Win7系统64位环境下使用Apache——Apache2.2安装及常见问题解决
- tcltk打开应用程序exe对比
- Spring boot 框架介绍
- Unity之C#注入
- WPF+MVVM数据绑定问题集锦
- ADO.NET温习(一)
- EO-1 Hyperion/ALI简介
- 学习资料 数据查询基础