TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: All
from: Peter Leschev
date: 1996-08-15 19:54:50
subject: possible floating point error in BC

Hi!
        I'm in high school and I recently competed in a national 
(In Australia) programming competition through my school. I got 4 of the 5
questions done (in the 2 hours). But one of the questions involved reciprocal
numbers. You had to write a program to locate the numbers between 101 and 999
for which the reciprocal contains the digit set 1996 and determine the position
at which the set begins. The question also stated that the program should be
able to handle numbers to 500 decimal places.
        There was a similar question the year before so I was ready for it
(although that question was alot harder). I decided to use borland's function
to convert a floating point number to a string and to find the digit set from
there but for some reason borland only converted at most 20 decimal places =(

                Does anyone know of this limitation?????

         Is there any mathematical way to work this problem out?

I have supplied my proggie to show you what I have done. Please do not laugh
too hard as I was under pressure of a comp and I'm only a kid! =)

--------------------------->8-----------------------------------------------

#include 
#include 
#include 
#include 

main()
{
        int number;
        long double actualnumber;
        char string[1024];
        int decimalplaces=100;
        int dec,sign;
        int place;


        printf("Problem No 5 - RECIPROCAL SEQUENCE\n\n");
        printf("Barker College\nHornsby\n2077\n\n\n");
        printf("Senior Team:\n\n");
        printf("Peter Leschev                21 AUG 1979\n");
        printf("Julian Moorehouse            13 JAN 1979\n");
        printf("Chris Sherlock		      7 APR 1979\n");
        printf("\n\n");

        printf("Please note: Due to Borland's limitations in their
ecvt function which converts floating point numbers to strings, only approx
20 decimal places were converted to a string and thus our program was
limited to that many decimal places.\n\n\n"

        for(number=101;number<=999;number++)
        {
                actualnumber=(long double)1/(long double)number;

                strcpy(string,ecvt(actualnumber,decimalplaces,&dec,&sign));

                for(place=0;place<=90;place++)
                {
                        if(string[place]=='1' &&
string[place+1]=='9' && string[place+2]=='9' &&
string[place+3]=='6')
                        {
                                printf("The reciprocal of %d contains
1996 beginning at position %d",number,place+dec+5);
                        }
                }
        }

        return;
}

---------------------------------------------------->8------------------------

Can anyone help?

CYA!


... A feature is a bug with seniority.
--- FMail/386 1.02+
* Origin: Lateline BBS, Sydney; +61-2-9579-6564; 24 hours; 33.6k (3:712/841)
SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 430 808 809 932 934
SEEN-BY: 712/311 407 505 506 515 517 624 704 816 824 828 841 844 852 713/888
SEEN-BY: 714/906 800/1
@PATH: 712/841 624 515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.