-1

Answered # Store large numbers in C

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

Asif_NSU 25 vegaseat 1,720 Lerner 582 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

-1

0

Big task.

Luckily, some people have already done some work.

http://www.swox.com/gmp/

If you want to implement on your own, then goodluck. I myself only implemented integers with trivial addition, subtraction and multiplication.

0

You could embed Python code in C++ and do the calculations with Python. 100+ digit integers are no problem. There is a little code snippet about the embedding of Python code into Dev-C++ at:

http://www.daniweb.com/code/snippet387.html

0

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.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...