工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
楼主: jinry

一个小算法...

[复制链接]
发表于 2007-8-8 17:47 | 显示全部楼层
原帖由 jinry 于 2007-8-8 14:10 发表


在纸上做一下这个1/7的除法运算吧..

   原来是我太懒了啊·····
回复

使用道具 举报

发表于 2007-8-8 17:49 | 显示全部楼层
原帖由 jieshao733 于 2007-8-8 17:47 发表

   原来是我太懒了啊·····

      听师兄一句话,胜问十个人啊 做了下除法,果然如此 又发现了自己一个缺点 可是被师兄笑掉大牙了
回复

使用道具 举报

发表于 2007-8-8 21:26 | 显示全部楼层
原帖由 jinry 于 2007-8-8 14:10 发表


在纸上做一下这个1/7的除法运算吧..

原来如此,学到东西了,原来我也很懒
回复

使用道具 举报

发表于 2007-9-20 23:01 | 显示全部楼层
不过如果是求第1位的话,15楼的算法还有漏洞
回复

使用道具 举报

发表于 2007-9-21 23:03 | 显示全部楼层
行过路过~
华为
回复

使用道具 举报

发表于 2007-10-3 12:16 | 显示全部楼层
1/7是8位循环小数,这个应该算是常识
回复

使用道具 举报

发表于 2007-11-24 15:16 | 显示全部楼层
#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

}
回复

使用道具 举报

发表于 2007-12-7 18:18 | 显示全部楼层

以下是我用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[r-1];
            Console.WriteLine("The result is {0}",result);
            Console.ReadLine();
        }
    }
}
回复

使用道具 举报

头像被屏蔽
发表于 2007-12-17 11:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 2007-12-18 23:00 | 显示全部楼层
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[0]);
                            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 Test  100
回复

使用道具 举报

发表于 2007-12-18 23:03 | 显示全部楼层
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[0]);
                                temp4 = Integer.p***Int(args[1]);
                            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 Test  100 3
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2024-6-13 04:00

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表