473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Infinite number addition and multiplication

Hi,
I am currently making a program which can add and multiply two numbers with infinite amount of digits.
The addition part of it I did by taking the input as a string and then one by one addiing the digits(with a carry) and putting the number in another string, till or both of them finishes.

the multiplication I dont know how to start it.
Suggestions or source code will be appreciated

Regards
Karan
Nov 24 '06 #1
2 8083
Banfa
9,065 Expert Mod 8TB
Hi,
I am currently making a program which can add and multiply two numbers with infinite amount of digits.
No I suspect you mean a very very large number of digits, if it were really infinite then you would never reach the end of the calculation.

OK spliting hairs aside you have a couple of options (I have done this sort of thing before myself).

The reason that the additional is easier is that you can do it on a column by column basis, you can't do that with multiplication, but you can take 1 of 2 approches.

Approcach 1: multiplcation is repeated addition for X * Y just add X to itself Y times.

Approcach 2: More complex but requires less computaion. If you are multiplying X by a single digit then you can do the multiplcation of a digit by digit basis for X. So multiply X by each digit in Y individually, remembering to add extra '0' to get the result in the correct place and then add the number of digits in Y results together to get the final result.

i.e. program the computer to do long multiplication

Expand|Select|Wrap|Line Numbers
  1. 648546
  2. x  123
  3.  
  4. = (648546 * 1 * 100) + (648546 * 2 * 10) + (648546 * 3)
  5.  
  6. = (64854600) + (12970920) + (1945638)
  7.  
  8. 64854600
  9. 12970920
  10. +1945638
  11. --------
  12. 79771158
  13.  
Nov 24 '06 #2
Thanks a lot it really helped .. I will be putting the code once I m ready with it.
Thanks and regards
Nov 29 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: jeffbernstein | last post by:
Greetings. I'm reading "How to think like a computer scientist: Learning with Python" and there's a question regarding string operations. The question is, "Can you think of a property that...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
37
by: Protoman | last post by:
Hi!!! Protoman here, I need to write an infinite precision number class b/c I want to compute pi. Give me some sample code. Also, when I run my program and it computes pi, will my computer freeze...
3
by: junaidnaseer | last post by:
Is it possible to actually count the number of addition or multiplication operations performed in a program during runtime . I know of a program that does this simply by looking through the code...
58
by: mailursubbu | last post by:
Hi How to write a program to get the factorial of 4096. I am working on a Linux m/c. Best Regards, Subra
109
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has...
10
by: bhipwell via AccessMonster.com | last post by:
Hello, I am stuck on this one. To illustrate my point, I will use cars as my example. I have a text field for which users can enter in anything they want. This particular field holds the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.