Asp.net returns the result of multiplying 1 to 20 with the same number. If the value is smaller than 50, the result is not displayed.

Source: Internet
Author: User

The instructor assigns assignments to Insus. NET, with the subject as the title.
Interested netizens can also exercise. Currently, the answer provided by Insus. NET is as follows, but the teacher has not read it yet. Therefore, it is not sure whether the answer is correct or the best. It is just for reference.
For the first time, implement the following in the fastest way:
Copy codeThe Code is as follows:
For (int I = 1; I <= 20; I ++)
{
Int j = I * I;
If (j> = 50)
Response. Write (I + "×" + I + "=" + j + "<br/> ");
}

The result is as follows:

After completing the above, Insus. NET immediately remembered that the teacher would not have such a simple problem. Will the teacher need Insus. NET to implement it? If the product is less than 50, the two digits are multiplied without loops, which reduces the performance. Therefore, immediately modify the program just completed:

First, obtain the number of square root of 50 and the number of Double data types. That is to say, a decimal number may appear, and convert it to Integer:
Copy codeThe Code is as follows:
Int min = (int) Math. Sqrt (50 );

In this way, we can know from which Integer the loop starts. But one day, instead of accumulating 50, the square root of the product is 8. If the square of 8 is 64, and the question is more than 64, the correctness starts from 9. The following judgment is true:
Copy codeThe Code is as follows:
If (Math. Pow (min, 2) <50)
Min + = 1;

The final answer to Insus. NET is as follows:
Copy codeThe Code is as follows:
For (int I = min; I <= 20; I ++)
{
Int j = I * I;
Response. Write (I + "×" + I + "=" + j + "<br/> ");
}

The result is the same as the first result.

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.