问题及代码:
/*
*copyright (c) 2014,烟台大学计算机学院
*all rights reserved.
*文件名称:test.cpp
*作者:赵敏
*完成日期:2014年10月16日
*版本号:v1.0
*
*问题描述:输入x的值,根据条件,输出y的值
*输入描述:一个x的值
*程序输出:对应的y的值
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x,y;
cin>>x;
if(x<2)
y=x;
else if(x>=2&&x<6)
y=x*x+1;
else if(x>=6&&x<10)
y=sqrt(x+1);
else
y=1/(x+1);
cout<<y<<endl;
return 0;
}
运行结果:
知识点总结:
运用if~else~嵌套语句。
学习心得:
开始时毫无头绪,经过同学的帮助有了思路。不过又出错了。。。。。唉。。好好努力吧