Override the odd sum between 1.

Source: Internet
Author: User

This time I made two changes to this code than the previous one. The first change was defined using the macro command # define. Thanks to @ garbageMan for this syntax.

The second change changes the first I + 2 to be determined using the if statement.

The Code is as follows:

         # include <stdio.h> # define BEGIN  # define END   main(            sum =      (i=BEGIN;i<=END;++           (i%==)          sum +=i;       printf(                

Code running step thinking, the sequence is 16 rows of I = BEGIN is 1, I <= END is 2, if step 3, 1% 2 = 1 of the 18 rows are run, sum + = I is run, and then the 16 rows of ++ I are run to end with one loop. (If 1% 2 = 1 is not valid, directly execute ++ I)

For ease of Self-calculation, change I <= END to I <= 10

1 -----> when I is 1, less than or equal to the END of STEP (2), perform step (3) I % 2 = 1, and run sum + = I. Sum is 0 plus I value 1, sum becomes 1, I is 1 + + I, I is 2. The first cycle ends.

2 -----> when I is 2 and is less than or equal to the END of STEP (2), the execution of STEP (3) I % 2 = 1 is not true, and the execution of ++ I, the second cycle ends. I is 3 at this time

3 -----> when I = 3, if I is less than or equal to the END of STEP (2), perform step (3) I % 2 = 1, and run sum + = I. Sum has changed to 1 in the first loop, and the value of I is 3. The value of sum after the third loop is 4, I is 3, and after ++ I, I is 4, the third cycle ends.

4 -----> when I = 4, if I is less than or equal to the END of STEP (2), the execution of STEP (3) I % 2 = 1 is not true, and the execution of ++ I, the fourth cycle ends. I is 5 at this time

5 -----> when I = 5, less than or equal to the END of STEP (2), perform step (3) I % 2 = 1, and run sum + = I. Sum has changed to 4 in the third loop, and the value of I is 5. The value of sum after the fifth loop is 9, I is 5, and after ++ I, I is 6, the fifth cycle ends.

6 -----> when I = 6, if I is less than or equal to the END of STEP (2), the execution of STEP (3) I % 2 = 1 is not true, and the execution of ++ I, the sixth cycle ends. I is 7 at this time

7 -----> when I = 7, if it is less than or equal to the END of STEP (2), perform step (3) I % 2 = 1 and run sum + = I. Sum has changed to 9 in the fifth cycle, and the value of I is 7. The value of sum after the seventh cycle is 16, and I is 7. After ++ I, I is 8, the seventh cycle ends.

8 -----> when I = 8, if I is less than or equal to the END of STEP (2), the execution of STEP (3) I % 2 = 1 is not true, and the execution of ++ I, the eighth cycle ends. I is 9 at this time

9 -----> when I = 9, if it is less than or equal to the END of STEP (2), perform step (3) I % 2 = 1 and run sum + = I. Sum has changed to 16 in the seventh cycle, with the I value 9, the sum value after the ninth cycle is 25, I is 9, after ++ I, I is 10, the ninth cycle ends.

10 ----> when I = 10, if I is less than or equal to the END of STEP (2), the execution of STEP (3) I % 2 = 1 is not true, and the execution of ++ I, the tenth cycle ends. I is 11 at this time

11 ----> when I = 11, the END less than or equal to step (2) is not valid and the for loop is stopped.

Bytes -----------------------------------------------------------------------------------

The odd number between the end result 1-10 is 25.

------------------------------------

If the above Code is incorrect, please see this blog's friends point out that your dial is the greatest help for me to learn.

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.