正在加载图片...
C++语言程序设计 例3-1编写一个求X的n次方的函数 数 include <iostream> 函数声明 的 using name space std double ower(double x, int n) int main 声明与使用 函数调用 cout < 5 to the ower 2 is < power (5, 2)<< endli double power (double x, int n) double val 1.0 函数定义 while (n val val*x; 5 to the power 2 return(val)i is 25C++语言程序设计 5 例3-1编写一个求x的n次方的函数 #include <iostream> using namespace std; double power (double x, int n); int main() { cout << "5 to the power 2 is " << power(5,2) << endl; } double power (double x, int n) { double val = 1.0; while (n--) val = val*x; return(val); } 函 数 的 声 明 与 使 用 5 to the power 2 is 25 函数声明 函数调用 函数定义
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有