473,796 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Infinite number addition and multiplication

4 New Member
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 8121
Banfa
9,065 Recognized Expert Moderator Expert
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
confusedKaran
4 New Member
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
7711
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 addition and multiplication have that string concatenation and repetition do not?" I thought it was the commutative property but "<string>"*3 is equivalent to 3*"<string>". Any ideas?
43
5605
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 fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in a loop, they either terminate, or repeat themselves. In the mythical halting problem scenario...
37
6374
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 b/c it's infinite precision? Thanks for the help!
3
5002
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 for * and + operators but the problem is that this program is fooled when we use if...else structures coz there might be a + in the if part but the if part of the statement might not be getting actually called in a particular execution of the...
58
6758
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
7651
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 7 digits in base 10. Is there a way to compute that information without actually evaluating the factorial?
10
2367
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 reply to the question "What model car do you own?" Since there are nearly infinite number of vehicle models out there, I have no intention of creating a restricted drop down or list box.
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10173
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.