第4章课后习题评讲.pptVIP

  • 0
  • 0
  • 约小于1千字
  • 约 14页
  • 2020-02-18 发布于福建
  • 举报
第4章 C++函数;本章主要内容; 1.编写函数,定义两个unsigned short int型的参数,返 回两个参数的商,其数据类型为short int。如果第二个参 数为0,输出错误提示信息。 short int Divd (unsigned short int a, unsigned short int b) { if (b == 0) return -1; else return a/b; };1.(con.) #includeiostream using namespace std; void main() { unsigned short int x, y; short int z; cout Enter 2 numbers:; cin xy; z = Divd(x, y); if (z-1) cout Answer: z; else cout Error, cant divide by zero!; return 0; };4,编写函数,求两个整数的最大公约数和最小公倍数。 方法1:直接循环的思想;4,编写函数,求两个整数的最大公约数和最小公倍数。 方法2:辗转相除法;4 con. 最小公倍数方法1:;4 con. 最小公倍数方法2:;5:编写递归函数,计算x的y(y0)次幂。 ;6:编写程序,要求输人四位数的年份、两位

文档评论(0)

1亿VIP精品文档

相关文档