Interview Questions for "matchstick" programmers-breaking inertial thinking

Source: Internet
Author: User

Note this question because you are more aware of the necessity and importance of breaking the "inertial thinking" to solve the problem. We should consider it from another angle when solving problems in the future.

From coolshell

The following is a C program that wants to output 20 minus signs. However, the careless programmer writes the code wrong and you need to modify the following code correctly. However,You can only add or modify one character.Three answers are provided.

12345 int n = 20; for(int i = 0; i < n; i--){    printf("-");}

The following is the correct answer --

12345678 // Solution 1: Add a negative sign to I in the For Loopfor(int i = 0; -i < n; i--) // Solution 2: Convert I -- into n -- In the For Loop --for(int i = 0; i < n; n--) // Solution 3: Convert <in the for loop to +for(int i = 0; i + n; i--)

 

 

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.