面向对象程序设计3研讨.ppt

面向对象程序设计3研讨

第三章 函数;本章主要内容;函数的声明;函数的声明;函数的调用;例3-1编写一个求x的n次方的函数; 运行结果: 5 to the power 2 is 25;例3-2 数制转换;#include iostream.h double power (double x, int n); void main(void) { int i; int value = 0; char ch; cout Enter an 8 bit binary number ; for (i = 7; i = 0; i--) { cin ch; if (ch == 1) value += int(power(2,i)); } cout Decimal value is valueendl; };double power (double x, int n) { double val = 1.0; while (n--) val *= x; return(val); } 运行结果: Enter an 8 bit binary number Decimal value is 105;例3-3编写程序求π的值;#includeiostream.h void main() { double a,b; double arctan(dou

文档评论(0)

1亿VIP精品文档

相关文档