有3个整数a b c 由键盘输入,输出其中最大的数。 C++源代码

2016-06-15 16:31:30  分类: c++程序设计第三版谭浩强课后答案  参与:

有3个整数a,b,c,由键盘输入,输出其中最大的数。

以下是此题的【c++源代码】,需要C源代码的点击进入

C++源代码1:

#include <iostream>
using namespace std;
int main ( )
  {int a,b,c;
   cout<<"please enter three integer numbers:";
   cin>>a>>b>>c;
   if(a<b)
     if(b<c)
       cout<<"max="<<c;
     else
       cout<<"max="<<b;
    else if (a<c)
        cout<<"max="<<c;
    else
        cout<<"max="<<a;
    cout<<endl;
 return 0;
  }

C++源代码2:
#include <iostream>
using namespace std;
int main ( )
  {int a,b,c,temp,max ;
   cout<<"please enter three integer numbers:";
   cin>>a>>b>>c;
   temp=(a>b)?a:b;                 /*  将a和b中的大者存入temp中 */
   max=(temp>c)?temp:c;            /*  将a和b中的大者与c比较,最大者存入max */
   cout<<"max="<<max<<endl;
   return 0;
  }


来源:c++程序设计第三版谭浩强课后答案

本文链接:http://www.wb98.com/cjia/post/cjia_3.9.html


本站文章搜索:

<< 上一篇下一篇 >>

搜索

Tags列表

赞助商链接