您的位置:首页 > 编程语言 > C语言/C++

【高精度算法】A/B 高精度除以低精度 保留小数

2016-07-22 11:19 281 查看
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
char s[10010];
int a[50001],sth[50001],p[10];
long long b,c;
int main(){
gets(s);
scanf("%d",&b);
int len=strlen(s),th=0,xs,bbb=0;
for(int i=0;i<len;i++)a[i+1]=s[i]-'0';
int j=0;
while(th<b && j<len){
th=th*10+a[++j];
}
printf("%d",th/b);
th%=b;
for(int i=j+1;i<len;i++){
th=th*10+a[i];
printf("%d",th/b);
th%=b;
}
printf(".");
for(int i=1;i<=4;i++){
th*=10;
p[i]=th/b;
th%=b;
}
if(p[4]>=5)p[3]++;
printf("%d%d%d",p[1],p[2],p[3]);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  高精度 c语言 算法 C++