if语句的嵌套 课后习题
2015-12-04 22:23
411 查看
项目一
代码:
/*if语句嵌套
分段函数求值*/
#include <stdio.h>
#include <math.h>
int main()
{
double x,y;
scanf("%lf",&x);
if(x<2)
y=x;
else if(x<6)
y=pow(x,2)+1;
else if(x<10)
y=sqrt(x+1);
else
y=1/(x+1);
printf("%.3lf %.3lf",x,y);
return 0;
}项目二
代码:
/*if语句嵌套
油量监控*/
#include <stdio.h>
#include <math.h>
int main()
{
double x;
printf("请输入油表读数(0-1):");
scanf("%lf",&x);
if(x<0||x>1)
printf("输入错误\n");
if(x<0.25&&x>0)
printf("油量偏低,车手注意\n");
if(x>=0.75&&x<=1)
printf("满油,请放心开车");
return 0;
}
代码:
/*if语句嵌套
分段函数求值*/
#include <stdio.h>
#include <math.h>
int main()
{
double x,y;
scanf("%lf",&x);
if(x<2)
y=x;
else if(x<6)
y=pow(x,2)+1;
else if(x<10)
y=sqrt(x+1);
else
y=1/(x+1);
printf("%.3lf %.3lf",x,y);
return 0;
}项目二
代码:
/*if语句嵌套
油量监控*/
#include <stdio.h>
#include <math.h>
int main()
{
double x;
printf("请输入油表读数(0-1):");
scanf("%lf",&x);
if(x<0||x>1)
printf("输入错误\n");
if(x<0.25&&x>0)
printf("油量偏低,车手注意\n");
if(x>=0.75&&x<=1)
printf("满油,请放心开车");
return 0;
}
相关文章推荐
- 南邮2015年程序设计周_个人股票信息管理系统
- jQuery插件——表单验证(jquery.validate.js)
- Coderforce 444cDZY Loves Colors(线段树)
- ProE/Creo免费插件 MCADEx Tools 6.0
- [置顶] PHP账号密码HashPassword加密方式破解代码实例
- 可变参数列表
- AngularJS的增删改查、state嵌套案例,不涉及服务端
- leetcode Basic Calculator
- Linux I/O多路转接之select函数
- IOS 拼接参数与URL
- LeetCode 28 : Implement strStr() (Java)
- java.io.StreamCorruptedException: invalid stream header错误的解决方法
- hibernate中的Query查询和criteria查询的区别
- 大学这三年
- hdoj Rightmost Digit 1061 (数学转换&&找循环节)
- linux下安装java以及eclipes的安装
- linux驱动之看门狗
- leetcode Power of Two
- Google Java编程规范
- 也聊缓存