- 2
C++ Prog 2 Perform Arithmetic Ope. on No. of Size Greater than that of Int Without Using any Data Type of Size Greater than int
C++ Program to Perform Arithmetic Operations on Numbers of Size Greater than that of Int Without Using any Data Type of Size Greater than Int.
24 Respuestas
+ 18
Consider the numbers as strings. Perform the operations on each character by converting them into corresponding int (subtract ASCII of '0').
For example,
While adding, start from the rightmost characters of both numbers and keep adding the equivalent int one by one. The sum should also be a string. Keep track of the extra 1 when the sum is greater than 9. In subtraction, keep track of the borrow when you're subtracting larger number from smaller number.
Got this assignment once upon a time and all I remember it freaked me out 😑
+ 16
You may get idea from here,
I've considered only two numbers of SAME length.
https://code.sololearn.com/c4cvASnmle85/?ref=app
+ 8
What the heck...
i lost after "without using any datatype" line.
+ 6
can you elaborate your question?
just to make it clear.
+ 6
Then that will support up to (2^64 - 1)
+ 5
Just make it clear and we will answer it.
+ 5
like what?
this is maybe...
int x=3;
int y=4;
int z=++x *y;
cout<<z; // output is 8
or it involves for loop?
+ 5
@Cyrus
ahh i see...😐
there is long int datatype in cpp.
is that what you mean @Harshit?
+ 5
Nope, it's computer does not support infinity.
+ 5
I have tried you cannot even do 2^16 on int
+ 5
try long it supports up to (2^32 - 1)
+ 5
use long long (not a standart)
http://stackoverflow.com/questions/26447010/how-to-print-numbers-bigger-than-232-in-32-bit-c
+ 5
Wow! there is long long? how much byte does it contains?
+ 5
@Cyrus
try this link
http://en.cppreference.com/w/cpp/language/types
+ 5
yes
+ 4
can't do that. use long (if there is any in c++)
int is 4 bytes max.
+ 4
@Agus Mei He wants to do something like this
int i = 2e9999999 or 2000000000..... ;
he wants unlimited integer.
+ 3
You could also create an array of ints and perform arithmetic on that (use each element in the array as a digit that ranges from 0 to 9 and carry over into the next element). I've managed to track integers with 1000 digits using that methodology but adding and multiplying them is much easier than doing things like square root so I depends on what you want to use it for.
+ 2
practically I want to increase the size of int datatype and perform Arithmetic Operations on it..
+ 2
@cyrus yup..
but is there anything through which I can increase the range of int datatype explicitly?