plz help me with these question and l don't have a clue to t

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
kuul
Newbie
Posts: 5
Joined: Thu Jun 26, 2008 12:03 pm
Location: ghana
Contact:

plz help me with these question and l don't have a clue to t

Post by kuul »

write a program that weill divide two (2) N digit positve intergeres, where N may be arbitrarily large. your program should output the result of the divisioin and the remainde
sample input
enter a number 65656432310964579864321356898765432243578987876654
enter its divisor 94454

sample output
the quotient is 695115424555493466586584528963997631054047344
the remiander is 46478
kuull
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

As Burger 2227 explained to you in your next post, we believe that homework is a very necessary part of one's path towards learning, so, "we don't do homework". However, all here want to help others. It is our firm intention to help if you make an honest effort and post some code, explaining what specific problem you are having. We will then provide guides and explanations to help you advance with your code. This is based on the assumption that you want to learn how to code. If you have no interest in coding, you should not waste your time, and should get out of that class as soon as possible!
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

Oops, posted twice! Sorry. How does one delete such a second posting?
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
kuul
Newbie
Posts: 5
Joined: Thu Jun 26, 2008 12:03 pm
Location: ghana
Contact:

Post by kuul »

thanks you all and l am more than willing to to accept any assistance you are going to me. thnk you once more
kuull
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Deleting a post

Post by burger2227 »

To delete a recent post, just edit it and check the "Delete Post" box Ralph.

That will not work if it is a new thread post however! You can Delete posts only for a limited time too.

KUUL, INTEGERs (%) in QB can only be up to 32,767. LONG integers (&) can be be up to 2,147,483,647. Look up Integer division and MOD.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

Maybe this might work

Post by Kiyotewolf »

Divide your large number by a large numeric, 1000000000000000000, so that the number can fit inside of a Long-Int declaration. What you have to do to do this, is manually enter the decimal into the string, using string commands, then use the VAL expression to convert the over sized number into a Double Precision variable. Once you have the answer, round back to the same number of decimal places, then remove the decimal.

I don't wanna try attempting to code it cause I am afraid of huge numbers like that.. O.O
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
markm
Coder
Posts: 14
Joined: Thu May 01, 2008 11:08 am

Long division?

Post by markm »

Double precision arithmetic is only approximate, and no numeric data type I've ever heard of would take such long numbers without truncation. So to me, it sounds like the object of the assignment was to represent the very long numbers as strings or arrays of decimal digits and code the long division algorithm that you (should have) learned in elementary school. This will give exact results (including a remainder, or ending in a repeating decimal) for any number that will fit in memory. It is a tough problem.

Some hints: If the numbers come in as strings, convert to arrays of integers 0-9. For one digit D$, you get this value with ASC(D$)-ASC("0"). You also need a FOR loop and the MID$ function. You need three arrays; one is the dividend initially and then becomes the remainder, the second is the divisor, and the third is the result.

With pencil and paper, the toughest part of the algorithm is guessing the largest digit that, times the divisor, is less than or equal to the divisor or remainder. Instead of trying to code that, just subtract the divisor (suitably shifted left or right) until the remainder is less than the divisor; the number of times you subtracted is the result digit. This not only eliminates the guessing, but it also means you don't have to code multiplication as well.

Of course, if Kuul doesn't know how to subtract and divide with pencil and paper, he's got a problem...
Post Reply