实验2答案.docVIP

  • 74
  • 0
  • 约5.43千字
  • 约 9页
  • 2016-11-05 发布于重庆
  • 举报
实验2答案

实验2 选择和循环结构程序设计 求三个整数的最大值和最小值。 定义三个整形变量x1、x2、x3,并通过cin输入变量值 用if-else语句对三个整数进行比较,求出最大值和最小值 用cout显示计算结果 //参考一 #include iostream using namespace std; int main() { int x1,x2,x3,max,min; coutinput three numbers:; cinx1x2x3; //求最大值 if(x1x2) max=x1; else max=x2; if(x3max) max=x3; //求最小值 if(x1x2) min=x2; else min=x1; if(x3min) min=x3; //输出结果 coutmax(x1,x2,x3)=maxendl; coutmin(x1,x2,x3)=minendl; return 0; } //参考二 #include iostream.h void main() { int x1,x2,x3,max,min; cout请输入三个整数:endl; cinx1x2x3; if(x1x2) if(x1x3) max=x

文档评论(0)

1亿VIP精品文档

相关文档