2016.4.22上机内容.ppt

  1. 1、本文档共110页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
2016.4.22上机内容

2016.4.22 #includeiostream using namespace std; void main( ){ cout123456781234567812345678endl; cout1\t35\t22endl ; cout123\t3\t222endl ; } 下面是上节课讲的内容 附加题 检测你前面学过的内容。 注意 一定要先做再验证,才有效果。 #includeiostream using namespace std; void main( ){ int a=3,b=5; a=a^b; b=b^a; a=a^b; couta=a b=bendl; } #includeiostream using namespace std; void main( ){ cout94endl; cout(94)endl; } #includeiostream using namespace std; void main( ){ cout(34 27)endl; } #includeiostream using namespace std; void main( ){ cout( -12 2 )endl; } #includeiostream using namespace std; void main( ){ cout( 26 |14 )endl; } #includeiostream using namespace std; void main( ){ cout( 18 ^22 )endl; } * * * * 修改返回类型 #include iostream using namespace std; //计算x的n次方 int power (double x, int n) { double val = 1.0; while (n--) val = val*x; return(val); } int main( ) { cout 5.6 to the power 2 is power(5.6,2) endl; return 0; } * 注意:不要这样做 * * #include iostream using namespace std; double power (double x, int n); void 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); } * * //double power (double x, int n); 如果屏蔽这一句,编译出错。 error C2065: power : undeclared identifier * * 例3-2 数制转换 题目: 输入一个8位二进制数,将其转换为十进制数输出。 例如 11012 = 1*(23) + 1*(22) + 0*(21) + 1*(20) = 1310 所以,如果输入1101,则应输出13 * #include iostream using namespace std; double power (double x, int n); int main( ) { int value = 0; cout Enter an 8 bit binary number ; for (int i = 7; i = 0; i--) { char ch; cin ch; if (ch == 1) value += static_castint(power(2,i)); } cout Decimal value is valueendl; return 0; } double power (double x, int n) { double val = 1.0; while (n--) val *= x; return(val); } * * * 也可以这样写 if (ch == 1) value += int (power(2,i)); if (ch == 1) value += static_castint(power(2,i)); * * 读程序

文档评论(0)

yy558933 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档