Pat---1001. A + B format (20)

Source: Internet
Author: User

# Include <stdio. h> int main () {// defines the two integers int A and B to be read; // defines the array int D used for release and removal [9]; // read two integers scanf ("% d", & A, & B); // sum int ans = a + B; // if the sum is a negative number, output a negative number, and convert the sum to a positive number. If (ANS <0) {printf ("-"); ans =-ans;} // if the sum is smaller than 1000, directly output if (ANS <1000) {printf ("% d \ n", ANS);} else {// intends to split this and int zz = 0; while (ANS> = 1000) {d [zz] = ans % 1000; // obtain the remainder. The remainder is first placed in the array ++ ZZ; // array subscript + 1 ANS/= 1000; // operator} d [zz] = ans; // put the operator after calculation into the last printf ("% d", d [zz]) of the array; // first output vendor // inverted output for (INT I = zz-1; I> = 0; I --) {printf (", % 03d ", d [I]) ;}} return 0 ;}

The final running result is as follows:

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.