c++语言 幂指数,C++ pow(指数函数):求x的y次幂的值

C++pow

area = pow(4.0,2);

e97ee5d3adba40a42d022120f3d4e51a.jpg

图 1 pow 函数的返回结果

area = pow(4.0,2)

Area = 423

x = 3 * pow(6.0, 3);

cout << pow(5.0, 4);

83f8f55eff7aac9ed7efb11c49b92c41.jpg

图 2 可以将 pow 函数理解为一个“黑箱”

程序必须包含 cmath 头文件;

在传递给函数的两个参数中,至少第一个参数应该是 double 类型的,当然也可以两个都是;

因为 pow 函数返回一个 double 值,所以被赋值的任何变量也应该是 double 类型的;

area = pow(4.0, 2);// This program calculates the area of a circle. The formula for the area of a circle is PI times the radius squared. PI is 3.14159. #include

#include // Needed for the pow function

using namespace std;

int main()

{

double area, radius;

cout << "This program calculates the area of a circle. \n";

// Get the radius

cout << "What is the radius of the circle? ";

cin >> radius;

// Compute and display the area

area = 3.14159 * pow(radius, 2);

cout << "The area is " << area << endl;

return 0;

}

This program calculates the area of a circle.

What is the radius of the circle? 10

The area is 314.159

area = 3.14159 * radius * radius;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值