有一个函数如下 写一程序 输入x 输出y值 C++源代码

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

  有一个函数如下:
        {  x           (  x<1  )
 y={   2x-1      ( 1<=x<10 )            
        {  3x-11     ( x>=10 )

 写一程序,输入x 输出y值

以下是此题的【c++源代码】,需要C源代码的请点击
#include <iostream>
using namespace std;
int main ( )
  {int x,y;
   cout<<"enter x:";
   cin>>x;
   if (x<1)                           
      {y=x;
       cout<<"x="<<x<<", y=x="<<y;
      }
   else if (x<10)                     // 1≤x<10
       {y=2*x-1;
        cout<<"x="<<x<<", y=2*x-1="<<y;
       }
        else                           // x≥10
         {y=3*x-11;
          cout<<"x="<<x<<", y=3*x-11="<<y;
         }
    cout<<endl;
 return 0;
}

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

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


本站文章搜索:

<< 上一篇下一篇 >>

搜索

Tags列表

赞助商链接