C ++ FAQ: if, while, do-while, for is not required, All integers greater than 0 and less than K are printed. Void printless (int K) is a function prototype );

Source: Internet
Author: User

During the written test, I thought about how to implement the function by defining a class and using its automatic execution feature of constructor. However, if I want to do that, I certainly did not meet the requirements of the question.

After returning to school, I thought about the solution to this question from time to time and finally came up with a solution.

Solution 1: recursion (just come up)

# Include <iostream> using namespace STD; void printless (int K) {Switch (-- k) {Case 0: return; default: cout <k <Endl; printless (k) ;}int main () {printless (10 );}

Solution 2: Category

Class test {public: static int K; test () {cout <k ++ <Endl ;}}; int test: K = 1; void _ printless (int K) {test T [k-1];}



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.