In the program, it can calculate the summation and subtraction of two integers.
The integer can have 100 digits and can also be negative. How can i do this ?
In the program, it can calculate the summation and subtraction of two integers.
The integer can have 100 digits and can also be negative. How can i do this ?
Write say 20 digits down on paper and another 20 or so digits.
Now add them.
Do the same in your compurter program but use arrays and for loops and so on.
Happy computing
There are many cases exist, such as
1) -250+30
2) -25-(-30)
3) 25-30.....etc
how can i consider each cases ?
This isn't so easy.Even long integer cannot hold the complete length of the input you are assuming so we need to split the number into digit basis and proceed.
1>Take three array's A , B and C of size 100 each and initialize all their values to 0.
2>Take the input as A[0]=Units place of 1st number,A[1]=Tens place of 1st number and so on...(The same path to be followed for 2nd number with array B).
3>Take a int variable carry which is set to 0 initially.
4>if(A>B)
perform C=A-B;
// Remember carry is 0 only it is not manipulated
5>if(A<B)
set carry=1;
A=10+A;
now perform C=A-B;
6>In every loop check if carry is 1 (that is in the previous instance required a carry for subtraction) if not continue with step 4 or 5 which ever is proper.
7>If carry is 1 then perform:
A=A-1; // i is present count of loop
And then move on with step 4 or 5 which ever is proper
I suppose this is enough to give you a start.Now go on building this idea or a better idea of your own.(This idea still needs work and is not complete.)
>how can i consider each cases ?
By understanding them. If you don't understand what's going on then you clearly can't tell the computer how to do it. If you do understand what's going on, you can make such connections as realizing that -25-(-30) is actually the same as -25+30, you can move toward the sign of the second operand, and that the difference between negative and positive is the same as setting a flag and reversing direction when you hit 0.
Beyond that it's the same old basic arithmetic that you learned in the first grade.
> Beyond that it's the same old basic arithmetic that you learned in the first grade.
Do they still teach that?
Apparently not
http://www.literacytrust.org.uk/Database/businessupdate.html
The CBI surveyed more than 500 companies with 1.1million employees. They found that 52% of employers are dissatisfied with the basic literacy of school leavers and 50% with their basic numeracy, but 92% are satisfied with their IT skills. Half of employers said some teenagers were ‘unable to function in the workplace’ claiming they cannot make simple calculations in their heads, speak in an articulate manner or understand written instructions.
What's 92% measuring?
"Has the ability to switch the machine on, and move the mouse without strangling themselves with the cord".