问题及代码:
/*
*Copyright (c) 2014,烟台大学计算机学院
*ALL right reserved
*文件名;test。cpp
*作者;李莉
*完成日期2014年10月13日
*版本号v1.0
*
*问题描述:计算函数的值,当x>=1时。y=x-1,否则y=-x+1
*输入描述:一个整数x
*程序输出:对应的y值
*/
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin >>x;
if (x>=1)
y=x-1;
else
y=-x+1;
cout <<y<<endl ;
return 0;
}
运行结果:
知识点总结:个人认为最重要的一点是条件语句的判断
学习心得:自从上了贺老的C++,妈妈再也不用担心我的编程了