计算浮点数相除的余数C语言,请教一下,如何计算浮点数相除的余数

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

var

w,i,l,j,d1,d2,d,l1,l2,x2,x1,num,f:longint;

st,s1,s2,s,ans:string;

a1,a2:array[1..20]of longint;

k1,k2:int64;

begin

readln(st);

w:=pos(' ',st);

l:=length(st);

j:=0;

d1:=0;d2:=0;

s1:='';s2:='';

for i:=1 to w-1 do

if st[i]='.' then begin d1:=i;end;

for i:=w+1 to l do

if st[i]='.' then begin d2:=i-w;end;

if d1

then begin

d:=d2;

for i:=1 to d-d1 do a1[i]:=0;

for i:=1 to d1-1 do a1[i+d-d1]:=ord(st[i])-48;

for i:=d1+1 to w-1 do a1[d+i-d1-1]:=ord(st[i])-48;

l1:=d+w-1-d1-1;

for i:=w+1 to d2+w-1 do a2[i-w]:=ord(st[i])-48;

for i:=d2+w+1 to l do a2[i-1-w]:=ord(st[i])-48;

l2:=l-1-w;

end

else begin

d:=d1;

for i:=1 to d1-1 do a1[i]:=ord(st[i])-48;

for i:=d1+1 to w-1 do a1[i-1]:=ord(st[i])-48;

l1:=w-2;

for i:=1 to d-d2 do a2[i]:=0;

for i:=w+1 to d2+w-1 do a2[i+d-d2-w]:=ord(st[i])-48;

for i:=d2+w+1 to l do a2[i+d-d2-1-w]:=ord(st[i])-48;

l2:=l+d-d2-1-w;

end;

if l1>l2

then begin l:=l1;for i:=l2+1 to l1 do a2[i]:=0;end

else begin l:=l2;for i:=l1+1 to l2 do a1[i]:=0;end;

for i:=1 to l do

begin

s1:=s1+chr(a1[i]+48);

s2:=s2+chr(a2[i]+48);

end;

val(s1,k1);

val(s2,k2);

num:=k1 mod k2;

str(num,s);

ans:='';

w:=l-d+1;

j:=0;

for i:=length(s) downto 1 do

begin

if j=w then ans:='.'+ans;

ans:=s[i]+ans;

inc(j);

end;

if j

then begin

while j

begin

ans:='0'+ans;

inc(j);

end;

end;

if j=w

then begin

ans:='0.'+ans;

end;

s:='';

f:=0;

for i:=length(ans) downto 1 do

if f=0

then begin

if ans[i]<>'0'

then begin

s:=ans[i]+s;

f:=1;

end;

end

else s:=ans[i]+s;

writeln(s);

end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值