在纸上做一下这个1/7的除法运算吧..
原来是我太懒了啊····· 原帖由 jieshao733 于 2007-8-8 17:47 发表
原来是我太懒了啊·····
听师兄一句话,胜问十个人啊 做了下除法,果然如此 又发现了自己一个缺点 可是被师兄笑掉大牙了 原帖由 jinry 于 2007-8-8 14:10 发表
在纸上做一下这个1/7的除法运算吧..
原来如此,学到东西了,原来我也很懒 不过如果是求第1位的话,15楼的算法还有漏洞 行过路过~
华为 1/7是8位循环小数,这个应该算是常识 #include<stdio.h>
#include<conio.h>
void main()
{
int temp,m,n,k,i;
while(1)
{
printf("请输入一个被除数\n");
scanf("%d",&m);
printf("请输入一个除数\n");
scanf("%d",&n);
temp=n%m;
printf("第1位的余数是:%d\n",temp);
for(i=2;i<=100;i++)
{
temp=(temp*10)%m;
k=temp*10/m;
printf("第%d位的余数是:%d\n",i,k);
}//for
getch();
}//while
}
以下是我用C#做的结果,请看
using System;using System.Collections.Generic;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
int a1=1;
int a2=4;
int a3=2;
int a4=8;
int a5=5;
int a6=7;
int[] array=new int[]{a1,a2,a3,a4,a5,a6};
int s=6;
int r=100%s;
int result=array;
Console.WriteLine("The result is {0}",result);
Console.ReadLine();
}
}
} public class Test{
public static void main(String[] args) {
int i=1;
int temp1=0;
int temp2=1;
int temp3=0;
try{
temp3 = Integer.p***Int(args);
while(i!=temp3){
temp2 = temp2*10%7;//求得余数
i++;
}
temp1 = temp2*10%7;
temp1 = temp2*10-temp1;//第九十九位乘十减余除七
temp1 = temp1/7;
System.out.println(temp1);
}
catch(NumberFormatException e){
System.out.println(e);
}
}
}
运行java Test100 public class Test{
public static void main(String[] args) {
int i=1;
int temp1=0;
int temp2=1;
int temp3=0;
int temp4=0;
try{
temp3 = Integer.p***Int(args);
temp4 = Integer.p***Int(args);
while(i!=temp3){
temp2 = temp2*10%temp4;//求得余数
i++;
}
temp1 = temp2*10%temp4;
temp1 = temp2*10-temp1;//第九十九位乘十减余除七
temp1 = temp1/temp4;
System.out.println(temp1);
}
catch(NumberFormatException e){
System.out.println(e);
}
}
}
运行java Test100 3
页:
1
[2]