C++指数函数

如何利用指数函数,指数是整形变量

c里面函数原型是double
pow(double,double),需要包含math.h。
c++里面推荐这样用(包含iso
c++从c继承的数学函数库,但头文件不带.h扩展名且前面加c,需要用namespace
std,函数原型与c中相同):
#include<cmath>
//添加需要包含的头文件...
using
namespace
std;
int
main()
{
double
d,a=2,b=3;
d=pow(a,b);
//d=a^b
//添加代码...
return
0;
}
另外如果使用底数为e,可以用double
exp(double),用法与以上类似。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-25
math库中有pow(x,y)函数,x为底数,y为指数,返回值为结果,如下:
#include <stdlib.h>
#include <math.h>
#include<iostream>
using namespace std;
int main() {

int x, y, result;

cout<<"Enter x,y \n"<<endl;
cin>>x>>y;
result=pow(x,y);
cout<<"\nthe result is:"<<result<<endl;
system("pause");
return 0;
}本回答被提问者采纳
第2个回答  2009-03-17
#include <iostream>
using namespace std;
#include "math.h"
void main()
{
int a,b;
cin>>a>>b;
cout<<pow(a,b)<<endl;
}
第3个回答  2019-12-29
math库中有pow(x,y)函数,x为底数,y为指数,返回值为结果,如下:
#include

#include

#include

using
namespace
std;
int
main()
{
int
x,
y,
result;
cout<<"Enter
x,y
\n"<
>x>>y;
result=pow(x,y);
cout<<"\nthe
result
is:"<

评论
0

0

0

加载更多
相似回答