2016/7/6 real-precision calculator-Plus (Fire speed !!!), 2016 precision
I wrote it again ......
Source code:
# Include <stdio. h>
# Include <string. h>
Int a [1000] = {0}, B [1000] = {0 };
Int main (void)
{
Char s1 [1000], s2 [1000]; // set two strings s1, s2
Int l1 = 0, l2 = 0, l, I;
Scanf ("% s", s1 );
Scanf ("% s", s2); // enter the value of char string s1
L1 = strlen (s1); // assign the value of s1 length to l1
L2 = strlen (s2); // assign the value of s1 length to l2
For (I = 0; I <= l1-1; I ++) // for _ assign s1 to the array
{
A [l1-1-i] = s1 [I]-'0 ';
}
For (I = 0; I <= l2-1; I ++) // for _ assign the string s2 that cannot be computed to array Calculation
{
B [l2-1-i] = s1 [I]-'0 ';
}
If (l1> l2) // judge the string length and compare the size accordingly.
{
L = l1;
}
Else
{
L = l2;
}
For (I = 0; I <= L-1; I ++) // The arrays a [I] And a [I] are calculated by the for loop and assigned to a [I].
{
A [I] = a [I] + B [I];
If (a [I]> = 10) // judge the carry condition and add the position.
{
A [I + 1] = a [I + 1] + 1;
A [I] = a [I]-10;
}
}
If (a [l]! = 0) // determine whether the first digit is carry
{
L ++; // pave the way for changing the array position of the subsequent Program
}
For (I = L-1; I> = 0; I --) // reverse output returns the original reverse
{
Printf ("% d", a [I]);
}
Return 0;
}
Author's comment:
This high-precision calculator is an infinite addition, no matter how big it is, it can be added up once. After feedback, I corrected the disadvantage of too bright font. This time, the copied code may be unavailable due to the copy link card segment of the blog, source code c source files will be updated within 1-3 days!
Please leave a comment if there are any mistakes.
Then, submit it!
ByHe_He _S
Group @ Chengdu Qizhong high-tech OI2015
Modified at | first time |
Modified at | second |
This document will be updated within 1-3 days.