3.2选择结构.pptVIP

  • 5
  • 0
  • 约5.78千字
  • 约 18页
  • 2016-12-29 发布于江苏
  • 举报
§3.2选择结构 1.基本形式(三种) ? 2.例子 ? [例1]输入24小时制的时间,转换并输出12小时制的时间并注明是上午还是下午(上午用A.M表示,下午用P.M表示) #includeiostream.h void main() {?? float x; ??? cout”Enter the hour please:”; ??? cinx; ??? if(x12) ??????? {?? cout”P.M:”; ??????????? x=x—12; ??????? } ??????? else cout”A.M:”; ??????? coutx‘\n’; } (改进) #includeiostream.h void main() {???float x; ??? cout”Enter the hour please:”;cinx; ??? if(x=12) cout”A.M:”; ?? else{cout”P.M:”; x=x—12;} ??? coutx‘\n’; }//注意书写层次结构 [例2]从键盘上输入3个数A,B,C,求出三数中最大者并输出。 源程序如下: #includeiostream.h void main() {int A,B,C,max; cout”Enter

文档评论(0)

1亿VIP精品文档

相关文档