How to express the nth power of a in C language

下次还敢
Release: 2024-04-27 22:09:37
Original
1131 people have browsed it

In C language, the pow() function is used to calculate the nth power of a. The base a needs to be used as base and the exponent n needs to be passed to the function as exponent. For example, to calculate 2 raised to the 5th power, call pow(2, 5).

How to express the nth power of a in C language

The nth power of a in C language

In C language, use the pow() function to calculate a to the nth power. The prototype of this function is:

double pow(double base, double exponent);
Copy after login

where:

  • base: base a
  • exponent: exponent n

To calculate a To the power n, you simply pass a as the base and n as the exponent to the pow() function. For example:

#include  #include  int main() { // 计算 2 的 5 次方 double result = pow(2, 5); // 输出结果 printf("2 的 5 次方是 %f\n", result); return 0; }
Copy after login

Output:

2 的 5 次方是 32.000000
Copy after login

Note:

    ##pow() function returns a double type value.
  • If exponent is negative, the function will return NaN (not a number).
  • If base is 0 and exponent is negative, this function will return infinity.

The above is the detailed content of How to express the nth power of a in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!