2016/7/6 true & #183; high-precision calculator-Plus (Fire speed finished !!!), 2016 precision

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.