please how do i store large numbers in c. the number has no be large like 121223824824623423476234762347623423476234234342342332762376 maybe up to 100 digits or more. after storing the number i need to carry out mathematical operations on that number which of course has been stored in a variable. mathematical operations like %(modular), and (pow), because as i understand, pow only operates with double while modular works with only integer variables

11 Years
Discussion Span
Last Post by Lerner

Big task.
Luckily, some people have already done some work.
If you want to implement on your own, then goodluck. I myself only implemented integers with trivial addition, subtraction and multiplication.


If you want (or need) to slug it out yourself instead of using someone else's solution, one way is to represent the very large number using an array of char (ie a string). Each char represents a place holder in the actual int. The trick then becomes how to convert char/string to int and back again, and how to deal with carryovers and borrowing. Start out by developing the technique for 2 or 3 digit numbers, then generalize. You can probably get a reasonable idea of how to proceed by searching the board for posts like Huge numbers, or Big numbers.

Classes are useful for encapsulating everything you want to do to/on an object. For example, you can overload the % operator and the pow() function for a class just like you will overload the +-*/ operators for a class. And remember, modulo is just doing division over and over until the remainder is less than the divisor and then returning the remainder rather than whatever the other part of the dividend is called and pow() is just multiplication over and over again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.