Handling large numbers is an important issue in computer programming. Very often in number theory we need to deal with numbers of astronomical size and we are forced to rely upon computers for manipulation of such numbers. This article describes the method of handling very large numbers in C by showing how to find large exponentiation of numbers.
Exponentiation is one of the few mathematical operations which increase the number of digits extremely fast. In number theory we often need to find large exponentiation of a number, e.g. finding 25th Mersenne prime which involves calculation of 2^21701 having 6533 digits. Hence for the obvious reason we rely upon computers for calculating such big numbers. But it is not easy to handle numbers having such a huge magnitude since all standard programming languages use 32 bit (or 64 bit at maximum) arithmetic for integer operations and thus the maximum number of integers that can be stored in a computer memory is 2^32 (or 2^64) which is a mere 10 digit number. Floating point arithmetic, which uses 64 bit arithmetic, has a maximum precision of only 17 digits. In this article I will discuss the method of handling large numbers in “C” by showing how to find large exponentiation of a very large number.
The Method
The basic idea behind storing a very large number is to use arrays and manipulation of them is to be done using a base higher than base 10, e.g. 16, 64 or 100000. Higher is the value of base lesser is the number of operations for a particular calculation. Though we can use any positive integer (limited by the word length of a particular data type) as the base, it is convenient to use a base which is a multiple of 10. The main advantage of using such base is that we do not need to back convert the number into base 10 which is the base of the output we want. It is because the face value of a number in such base is same as its decimal value. Thus our strategy of finding exponentiation will be to store the input in an array of appropriate length and then multiply it required number of times.
A “C” Program
Let us consider the C code provided below utilizing the method discussed above. It takes the number and the exponent from user as input and prints the result. The inputs must be positive, since what the sign will be after exponentiation of a negative number, can be easily determined by noting whether the exponent is even or odd. Again negative exponents are not considered here because large negative exponents often lead to fractions which are to be handled in a different manner.
Here I have used base 1000. The trivial cases are dealt separately using “if” statements. The function “digit_count” counts the number of digits present in an integer. The length of the array is obtained by calculating the number of digits in the final answer using the inbuilt function “ceil” which basically returns the smallest integer that is not less than its argument. The major step is to determine the multiplication which is done by calling function “multiply” shown below. While displaying the result it is taken care of to print some required leading zeros for some array elements.
A typical output will look like follows.
Few Limitations
In spite of the algorithm being perfectly fine the inputs are limited due to the fact that a computer uses 32 bit arithmetic so that each array element can store a maximum value max=2^321=4294967295. If “b” be the base used in the program then the input number “n” is limited by max/(b1). Since we have used b=1000, the maximum value of n=4299266, an input value greater than this may give erroneous result. There is no limitation on the exponent except the value max=4294967295. However the program is fast enough to give the result within a fraction of second.
Thus we learned the method of handling large numbers in “C” and how to find large exponentiation of very large numbers.
Note: If you are unable to see the images properly, please zoom in the page to view clearly.
x
will be notified of your question.
Your question will also be posted as a public question in the Knoji forums, so be sure to phrase it as a general question that anyone could answer. Personal questions and private messages should be sent using the Message Me feature instead.
Confirm your recommendation
x
By making this recommendation, you are confirming that you would recommend roytanay to people you know as an expert in the topic Computer Programming & Languages.
Confirm and recommendCancel
You have used your question credit for today. Please wait until midnight today for your question credits to renew.
x
To maintain a high standard for new discussions started, each Knoji member is limited to a certain number of questions each day. Use your questions wisely, ask quality questions and you'll get quality answers.
Credits refresh at midnight US Central time, at which time you'll receive your next day's allotment of credits.
Oops, you haven't confirmed your email yet
x
We've sent an email to your registration email address. You'll need to click the link in that email before you can post stuff on Knoji.
Didn't get the email? First, try checking your spam inbox. If you can't find it, click here and we'll resend your confirmation link.
Please confirm your email address
xWe've sent a confirmation link to your email address. Please check your email and click the link to confirm to your account.
Didn't get the email? First, try checking your spam inbox. If you can't find it, click here and we'll resend your confirmation link.
Great! Here's a preview of your question.
x
We've sent a confirmation link to your registration email address. Please click this link to confirm your email.
Your question will not be posted publicly until you confirm your email.
Didn't get the email? First, try checking your spam inbox. If you can't find it, click here and we'll resend your confirmation link.
Your confirmation email has been resent
x
Please check your email (check your spam inbox too) and click on the link provided to confirm your account with Knoji.
You have received 0 answer votes on Knoji
x
When people like the answers you provide, they make a public acknowledgement by placing a vote for your answer. The more votes you accumulate on Knoji, the higher you move up in rank. Increased rank gives you increased capabilities, more perks and more expert cred around the site.
Answer questions nowLearn more about user levels
Oops, you're out of question credits for today!
x
We limit the number of questions members can ask on Knoji each day in order to improve the quality of questions and answers. Your question credits will reset each day at midnight US Central time, so come back then to ask more questions!
Contributors on Knoji are awarded Levels as they establish themselves as experts within the community. There are three ways in which users can increase their level, via writing articles or via answering questions, or both.
Level
Article Track
Answer Track
Combined Track
Abilities
Member



Can publish articles, ask and answer questions
Contributor
Successfully publish first article
Must earn +50 votes
Publish first article OR +50 answer votes
Eligible for revenue sharing. Access to Dashboard.
Expert
Must publish 10 consecutive articles
Must earn +200 votes
10 articles OR +200 answer votes
Selfpublish and edit past articles. Increased compensation rate.
Guide
Must earn +500 recommendations
Must earn +1,000 votes
+250 article recommendations AND +500 answer votes
Increased earnings rate. Greater number of votes.
Authority
Must earn +1,000 recommendations
Must earn +5,000 votes
+500 article recommendations AND +2,500 answer votes
Increased earnings rate. Greater number of votes & question credits.
Pro
Must earn +5,000 recommendations
Must earn +10,000 votes
+2,500 article recommendations AND +5,000 answer votes
Increased earnings rate. Greater number of votes.
Master
Must earn +10,000 recommendations
Must earn +50,000 votes
+5,000 article recommendations AND +25,000 answer votes
Your primary job as an Ambassador is to kick off thoughtful discussion threads around products, services. Your discussions can be on any topic in Knoji's category system. Here are some examples of the types of discussions you'll be starting:
Requests for recommendations for any type of product or service, examples:
People on Knoji ask questions seeking recommendations for products and services. We encourage our community members to answer questions whenever you can make a useful recommendation towards any request.
When pointing to specific products, please link to specific product pages on Amazon.com or Walmart.com
UPDATE: Ambassadors earn bonuses for answering questions, however  only answers which include products links (as described above) will earn bonuses.
You should include screenshots of the products you recommend (Ambassadors: you earn increased rewards when doing this)
Try to recommend products that you've had personal experience with. If not, it is acceptable to recommend products or options based on thorough research you do online.
People on Knoji ask questions seeking recommendations for products and services. We encourage our community members to answer questions whenever you can make a useful recommendation towards any request.
When pointing to specific products, please link to specific product pages on Amazon.com or Walmart.com (Ambassadors: You earn increased rewards when doing this)
You should include screenshots of the products you recommend (Ambassadors: you earn increased rewards when doing this)
Try to recommend products that you've had personal experience with. If not, it is acceptable to recommend products or options based on thorough research you do online.
Asking questions
On Knoji, you can ask any question about any consumer or shoppingrelated topic. Many questions involve requests for recommendations for any type of product or service, examples:
x
To qualify as a working coupon, the link or code must provide a discount above and beyond what's freely available by default on the vendor's site.
To check this, first click the link and check that the coupon can be applied and does provide the discount described. Then, in a different browser, open the vendor's site (without using the Knoji link) and check whether that same discount is available to any user by default. If it's not, and the coupon works, then you've found a qualified coupon and can verify it and get your earnings. If not, you can verify that it does not work (explain why this is) and you'll earn a smaller credit.
Don't waste your time verifying invalid coupons! Before you receive payment, all your verifications will be reviewed, and if they are invalid, you earnings will be deleted. Verify only valid coupons in order to receive payment for this project.