asp.net shows 1 to 20 of the same number multiplication results, if the value is smaller than 50 does not show _ practical skills

Source: Internet
Author: User
Tags square root
The teacher assigned homework to Insus.net to do, topics such as title.
Interested users can also practice. Now Insus.net's answer is as follows, but the teacher has not looked, so the answer is correct or the best, is not sure, but for reference.
The first time the fastest way to achieve:
Copy Code code as follows:

for (int i = 1; I <= i++)
{
Int J = i * I;
if (J >= 50)
Response.Write (i + "x" + i + "=" + j + "<br/>");
}

The results were as follows:

Upon completion of the above, Insus.net immediately remembered that the teacher must not have such a simple question. Will the teacher to insus.net implementation, the product is less than 50 of the two numbers multiplied by the need to cycle, to reduce performance, so immediately modify the program just completed:

First we find out the number of square roots of 50, and the data type of double, which means that there can be decimal, and convert it to integer:
Copy Code code as follows:

int min = (int) math.sqrt (50);

In this way, we can see which integer started the loop. But one day, it is no longer the calculated product is 50, but instead of the product 64, its square root is 8. If the square of 8 is just 64, and the title is greater than 64, the correct start is 9. So it's still the following judgment:
Copy Code code as follows:

if (Math.pow (min, 2) < 50)
min = 1;

The final insus.net answer is as follows:
Copy Code code as follows:

for (int i = min; I <= i++)
{
Int J = i * I;
Response.Write (i + "x" + i + "=" + j + "<br/>");
}

The result is the same as for the first time.
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.