鱼C论坛

 找回密码
 立即注册
查看: 1855|回复: 0

[技术交流] C语言分支结构程序设计

[复制链接]
发表于 2021-9-25 10:35:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
输入一个角度判断是否是tan90°和270°。
因为tan90°和270°是不存在的正切值。必须提示你90°和270°不存在

现包含MathApply.h头文件

  1. // This Math Apply header file
  2. #pragma once
  3. #include <stdlib.h>
  4. #include <math.h>

  5. #ifndef _MATH_H
  6. #define _MATH_H 0x01

  7. #define M_PI    3.14159265358979323846
  8. #define RAD     180                    // 弧度

  9. #define DRE30   0.52359877559829881566 // 30°
  10. #define DRE45   0.78539816339744827900 // 45°
  11. #define DRE60   1.04719755119659763132 // 60°
  12. #define DRE90   1.57079632679489655800 // 90°
  13. #define DRE180  3.14159265358979311600 // 180°
  14. #define DRE270  4.71238898038468967400 // 270°
  15. #define DRE360  6.28318530717958623200 // 360°

  16. // 角度集合
  17. int MathDregess[] = { DRE30, DRE45, DRE60, DRE90, DRE180, DRE270, DRE360 };

  18. /*
  19. * 度数转小数
  20.         * 1°=pi/180 rad=3.141592653589793/180=0.01745329252
  21.         * 度数 乘 π 除 弧度 = 小数
  22. */
  23. #define DregreeToDecimal( DRE ) \
  24.         (DRE * M_PI / RAD)

  25. #endif
复制代码


  1. #include <stdio.h>
  2. #include "MathApply.h"

  3. int main ( int argc, char *argv [] )
  4. {
  5.         double expression,
  6.         degress;

  7.         printf("Please input degrees: ");       // 接受用户输入,角度数。
  8.         scanf("%lf", &degress);

  9.         expression = tan(DregreeToDecimal(degress));
  10.         if ( expression == tan(DRE90) ||
  11.              expression == tan(DRE270) )        // 判断是否是90°和270°的角
  12.         {
  13.                 printf("tangent 90 degress And degress 270 is not exist!\n");
  14.         }
  15.         else
  16.         {
  17.                 printf("tan(%0.2lf) = %0.15lf\n", degress, expression);
  18.         }

  19.         return 0;
  20. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-26 03:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表