任务和代码:
/*
*Copyright (c)2015 CSDN学院
*All rights reserved
*文件名字:main.c
*作者:修红国
*完成日期:2015年11月10日
*版本号:V1.0
*
*问题描述:从键盘输入x的值(要求为实型),根据公式1计算并输出x和y的值
*<img src="https://img-blog.csdn.net/20150503212735008" alt="" />
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ( )
{
double x,y;
printf("输入x的值:");
scanf("%lf", &x);
if(x<2)
{
y=x;
}
else if(x<6)
{
y=x*x+1;
}
else if(x<10)
{
y=sqrt(x+1);
}
else
{
y=1.0/(x+1.0);
}
printf("x的值是:%lf\ny的值是:%lf\n",x,y);
return 0;
}
运行结果:
知识点总结:
if 语句嵌套的用法
心得: