Learn to edit code -- exercise solution 4 (Chapter 2 Exercise 7) of mad man C)

Source: Internet
Author: User

/* The father gives 2520 oranges to six sons. After the split, the father said, "the old man gave you 1/8 of the oranges to the second child. The second child gave the old man 1/7 of the oranges to the third child; after getting the old Three, they scored 1/6 yuan for the old four, and 1/5 yuan for the old four. After getting the old five, they scored 1/4 yuan for the old six; after getting the old six, we allocated 1/3 yuan to the boss together with the original oranges ". There is no orange score in the process of dividing oranges. As a result, there are just as many oranges in your hands. Ask the six brothers how many oranges they have. */# Include <stdio. h> # include <stdlib. h> # define limit 2520 # define fenshu 6 # define xd1_xd2 8 # define xd2_xd3 7 # define xd3_xd4 6 # define limit 5 # define limit 4 # define xd6_xd1 3int main (void) {int XD1, xd2, xD3, xd4, xd5, xd6; // The number of oranges of the brothers // The number of oranges in the hand is exactly the same. XD1 = xd2 = xD3 = xd4 = xd5 = xd6 = juzi_zongshu/fenshu; // xd6 = xd6/(xd6_xd1-1) * xd6_xd1; XD1-= xd6/xd6_xd1; // xd5 = xd5/(xd5_xd6-1) * xd5_xd6; xd6-= xd5/xd5_xd6; // xd4 = xd4/(xd4_xd5-1) * xd4_xd5; xd5-= xd4/xd4_xd5; // xD3 = xD3/(xd3_xd4-1) * xd3_xd4; xd4-= xD3/xd3_xd4; // xd2 = xd2/(xd2_xd3-1) * xd2_xd3; xD3-= xd2/xd2_xd3; // XD1 = XD1/(xd1_xd2-1) * xd1_xd2; xd2-= XD1/xd1_xd2; printf ("the number of oranges in the old hands of the six brothers is:"); printf ("% d \ n", XD1, xd2, xD3, xd4, xd5, xd6); System ("pause"); Return 0 ;}

Beginners often write code with one character at a time, which is not only inefficient but also prone to errors. You should learn to edit code efficiently and easily without errors. Take the code in this question as an example: // before giving the old six to the boss
Xd6 = xd6/(xd6_xd1-1) * xd6_xd1;
XD1-= xd6/xd6_xd1; red identifiers should be copied and pasted. This method is not prone to errors and is highly efficient. The two lines of code after "// old five to old six" should be copied after the first two lines of code, you can do this by searching, replacing, copying, and pasting. Subsequent lines of code should also be processed in accordance with the law.
Be sure to get rid of the character-by-character edit code habit.

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.