📄 小数问题.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0049)http://vip.6to23.com/dcyu/TurboC/algorithm/1.html -->
<HTML><HEAD><TITLE>Turbo C</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>BODY {
SCROLLBAR-FACE-COLOR: #ffffff
}
INPUT {
FONT-SIZE: 12px; FONT-FAMILY: "宋体"
}
INPUT {
FONT-SIZE: 12px; FONT-FAMILY: "宋体"
}
.border {
BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; COLOR: #000000; BORDER-BOTTOM: 1px dotted; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #efefef
}
.border {
BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; COLOR: #000000; BORDER-BOTTOM: 1px dotted; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #efefef
}
.input {
FONT-SIZE: 9pt; FONT-FAMILY: 宋体,Verdana, Arial, Helvetica, sans-serif
}
.links {
FONT-SIZE: 9pt; COLOR: #000000; FONT-FAMILY: 宋体,Verdana, Arial, Helvetica, sans-serif
}
</STYLE>
<META content="sumipntg 011, default" name="Microsoft Theme">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY text=#000066 vLink=#666699 aLink=#990099 link=#3333cc bgColor=#ffffff
background="">
<P> </P>
<DIV align=center>
<P><BR><A href="http://www.6to23.com/vip/asp/"><BR></A></P>
<TABLE height=24 cellSpacing=0 cellPadding=0 width=689 align=center border=0>
<TBODY>
<TR>
<TD width=94>
<P align=center><FONT color=#0000ff size=2> </FONT><A
href="http://vip.6to23.com/dcyu/TurboC/summarize.html"><FONT color=#0000ff
size=2>概述</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/basic.html"><FONT color=#0000ff
size=2>初级篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/advance.html"><FONT color=#0000ff
size=2>中级篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/senior.html"><FONT color=#0000ff
size=2>高级篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/sutra.html"><FONT color=#0000ff
size=2>经典篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/algorithm.html"><FONT color=#0000ff
size=2><SPAN
style="BACKGROUND-COLOR: #00ff00">算法篇</SPAN></FONT></A></P></TD>
<TD width=94>
<P align=center><FONT size=2> </FONT><A
href="http://vip.6to23.com/dcyu/TurboC/DS.html"><FONT color=#0000ff
size=2>数据结构</FONT></A></P></TD>
<TD width=100>
<P align=center><A href="http://vip.6to23.com/dcyu/index.html"><FONT
color=#0000ff size=2>回到首页</FONT></A> </P></TD></TR></TBODY></TABLE>
<TABLE height=542 cellSpacing=0 cellPadding=0 width=619 border=0>
<TBODY>
<TR>
<TD vAlign=top width=138 bgColor=#ffffff height=493>
<TABLE height=482 cellSpacing=0 cellPadding=0 width=686
background=小数问题.files/vccode.htm border=0>
<TBODY>
<TR>
<TD align=left width="100%" height=21>1.小数问题
<P><FONT
color=#0000ff>问题</FONT>:正整数相除用小数表示,有限小数直接写出结果,循环小数写出循环节。</P>
<P><FONT
color=#0000ff>算法</FONT>:本算法是根据计算正整数相除的运算规则而做的,需要判断的输出有:1.整数;2.有限小</P>
<P>数;3.纯循环小数;4.非纯循环小数。注意:不存在无限不循环小数。</P>
<P>如果计算出来的余数和商在以前出现过,就说明找到了循环节,因此以两个数组来存放每次运算</P>
<P>后的余数和商。</P>
<P>/*<BR>=======================================================================<BR>If
you input m and n, this program can tell you what m/n is.<BR>For
example : <BR>#1. 1/4=0.25<BR>#2. 7/6=1.1(6)<BR>#3.
3/7=0.(428571)<BR>=======================================================================<BR>*/<BR>#include
<stdio.h><BR>#include <conio.h><BR><BR>#define TRUE
1<BR>#define FALSE 0<BR><BR>void main()<BR>{<BR> unsigned int
i=0,j,t,s,m,n,k;<BR> unsigned int q[1000],r[1000];<BR> int
big,small=TRUE,flag=TRUE,limit=TRUE;<BR> scanf("%d/%d",&m,&n);<BR> t=m%n;
/* m div n 的余数
*/<BR> big=(m-t)/n;<BR> if(t==0)
/* m可以被n所整除,只输出整数部分 */<BR> {<BR>
printf("%d\n",big);<BR>
small=FALSE;<BR> }<BR><BR> if(t>0)
printf("%d.",big); /* m不能被n所整除,有小数部分,所以要打出小数点
*/<BR> q[0]=big;<BR> r[0]=t;<BR> do<BR> {<BR>
t=(r[i]*10)%n;<BR> i++;<BR>
q[i]=(r[i-1]*10-t)/n;<BR> r[i]=t;<BR>
for(j=1;j<i;j++) /* 寻找是否出现了相同的余数和商 */<BR> {<BR>
if(q[j]==q[i]&&r[j]==r[i])<BR>
{<BR>
flag=FALSE;<BR>
for(k=j;k<i;k++)<BR>
if(q[k]!=0)<BR>
{<BR> limit=FALSE; /* 非有限
*/<BR>
break;<BR> }<BR>
if(limit) /* 有限小数 */<BR>
{<BR>
for(k=1;k<i-1;k++)<BR>
printf("%d",q[k]);<BR>
printf("\n");<BR> }<BR>
if(!limit) <BR>
{ <BR> for(k=1;k<j;k++) /*
不是循环节的部分 */<BR>
printf("%d",q[k]); <BR>
printf("("); /* 循环从此开始 */<BR>
for(k=j;k<i;k++)<BR>
printf("%d",q[k]); /* q[k]是循环节 k=j……i-1
*/<BR> printf(")\n"); /* 循环从此结束
*/<BR> }<BR> }<BR>
}<BR> }<BR> while(flag&&small)
;<BR> getch();<BR>}</P>
<P><BR>程序:<A
href="http://vip.6to23.com/dcyu/TurboC/senior/mdivn.c"><FONT
color=#0000ff>mdivn.c</FONT></A><FONT
color=#0000ff>
</FONT><A
href="http://vip.6to23.com/dcyu/TurboC/algorithm/2.html"><FONT
color=#0000ff>下一页</FONT></A></P>
<P> </P></TD></TR>
<TR>
<TD align=left width="100%" height=21>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR align=center width=740 color=#8fb373 noShade SIZE=1>
<TABLE cellSpacing=0 cellPadding=0 width="90%" border=0>
<TBODY>
<TR bgColor=#949231>
<TD height=3></TD></TR></TBODY></TABLE>
<TABLE height=37 width=490>
<TBODY>
<TR>
<TD vAlign=top align=left width=486 height=8>
<P align=center><FONT size=2><FONT face=Arial>Copyright
2001-2002</FONT>,<FONT face=Arial>dcyu, All rights reserved</FONT>,
上次更新:2002-10-13</FONT> <FONT color=#000000><BR></FONT><FONT
color=#000080 size=2>E-mail : <A
href="mailto:dcyu@163.net">dcyu@163.net</A> QQ :
28009316 </FONT></P></TD></TR>
<TR>
<TD class=mainfont vAlign=top align=left width=486 height=17>
<P align=center><FONT size=2>建议使用IE 5.0以上版本进行浏览
最佳显示分辨率800*600</FONT></P></TD></TR></TBODY></TABLE> </DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -