How to input big integer in C? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to input big integer in C?

I want to take input a 100 digit number and then want to divide by 3.. How can I do this?

23rd Dec 2019, 11:34 AM
Abdullah Al Noman Sakib
Abdullah Al Noman Sakib - avatar
7 Answers
+ 3
23rd Dec 2019, 3:48 PM
Sp Maurya
Sp Maurya - avatar
+ 6
One way of doing it is with structure lists, such as a stack. Basically, you should create a structure which will store a digit of the input number and a link to the next structure which stored the next digit. It can also be helpful to store address of the previous digit structure. Using the division algorithm, you can actually perform the division, by going through the digits just as you would do by hand. Each resulting digit should be stored in a new stack. It is helpful to create functions which will take the stack and print it, or which will add a digit dynamically, and so on. Maybe it's best that you start by doing a sum function, which returns a new dynamically allocated stack storing the result. Then move on to the division procedure. I've already done something like this, and the way is indeed with structure stacks. Hope that was helpful!
23rd Dec 2019, 12:30 PM
Gonçalo Magalhaes
Gonçalo Magalhaes - avatar
+ 5
Yes you can, but there isnt any build-in library for that in C, if you can use java's bigInteger for simplicity otherwise you have to write it code by your own which is time consuming and hard, maybe you should search for pre-wrriten BigInteger manupliation code for C language in Google
23rd Dec 2019, 12:09 PM
Abdol Hashimi
Abdol Hashimi - avatar
+ 1
you need to save the number as a string and do divisions as a string here is a way to do it https://www.google.com/amp/s/www.geeksforgeeks.org/divide-large-number-represented-string/amp/
23rd Dec 2019, 2:25 PM
Shen Bapiro
Shen Bapiro - avatar
0
First of all you have to take the number input in a char array because int will overflow.... Then make a function which will divide it the same way as we divide a number on a notebook, we have to simulate the same prosiser in the form of code... if you want the code of that divide function... i will provide... ask me...
23rd Dec 2019, 1:41 PM
Sp Maurya
Sp Maurya - avatar
0
Hope this will help
23rd Dec 2019, 3:48 PM
Sp Maurya
Sp Maurya - avatar
- 2
You can use long or double int
25th Dec 2019, 10:57 AM
Ruchita Oza