Calculate the N power of a number without considering the big number problem.

Source: Internet
Author: User

Note the boundary condition or special circumstances:
1. The negative power of 0 cannot exist.
2. Generally, to the power of a negative number, you must calculate the power of a positive number and then divide it by 1.
3. Generally, the power of a number cannot be recycled. because of its low efficiency, it is best to use the square.


# Include <stdio. h> # include <stdlib. h> double normal_power (double data, int e) {double result; if (e = 0) return 1; if (e = 1) return data; result = normal_power (data, e> 1); result * = result; if (e & 0x1 = 1) result * = data; return result ;} double power (double data, int e) {double result; if (data-0.0>-0.0000001 & data-0.0 <0.0000001 & e <0) {// the negative power of 0 is returned-1;} if (e <0) {e =-e; result = normal_power (data, e ); result = 1.0/result;} else result = normal_power (data, e); return result;} void main () {printf ("% lf \ n ", power (2, 3); getch ();}


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.