第23讲项目4-三角公式求值

xiaoxiao2021-02-28  78

任务和代码

/* *Copyright (c)2017,学院 *All rights reserved. *文件名称: main.c *作 者: 伍志鹏 *完成日期: 2017年9月1日 *版本号: v1.0 * *问题描述: 求y值 (x值由键盘输入)。 * * y={(sin(x)+cos(x))/2,x>=0 * {(sin(x)-cos(x))/2,x<0 * *程序输出: y值 */ #include <stdio.h> #include <stdlib.h> #include <math.h> //需要用到三角函数,使用数学库 int main() { double x,y; //涉及到三角函数,使用浮点型 printf("请输入x的值:"); scanf("%lf",&x); if(x>=0){ y=(sin(x)+cos(x))/2; }else{ y=(sin(x)-cos(x))/2; } printf("y的值是:%lf\n",y); return 0; }

运行结果

知识点总结

该程序结合了三角函数来解决问题,解决三角函数的问题的时候,需要导入math.h数学库。

转载请注明原文地址: https://www.6miu.com/read-77918.html

最新回复(0)