鱼C论坛

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

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

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

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

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

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

现包含MathApply.h头文件
// This Math Apply header file
#pragma once
#include <stdlib.h>
#include <math.h>

#ifndef _MATH_H
#define _MATH_H 0x01

#define M_PI    3.14159265358979323846
#define RAD     180                    // 弧度

#define DRE30   0.52359877559829881566 // 30°
#define DRE45   0.78539816339744827900 // 45°
#define DRE60   1.04719755119659763132 // 60°
#define DRE90   1.57079632679489655800 // 90°
#define DRE180  3.14159265358979311600 // 180°
#define DRE270  4.71238898038468967400 // 270°
#define DRE360  6.28318530717958623200 // 360°

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

/*
* 度数转小数
        * 1°=pi/180 rad=3.141592653589793/180=0.01745329252 
        * 度数 乘 π 除 弧度 = 小数
*/
#define DregreeToDecimal( DRE ) \
        (DRE * M_PI / RAD)

#endif
#include <stdio.h>
#include "MathApply.h"

int main ( int argc, char *argv [] )
{
        double expression,
        degress;

        printf("Please input degrees: ");       // 接受用户输入,角度数。
        scanf("%lf", °ress);

        expression = tan(DregreeToDecimal(degress));
        if ( expression == tan(DRE90) ||
             expression == tan(DRE270) )        // 判断是否是90°和270°的角
        {
                printf("tangent 90 degress And degress 270 is not exist!\n");
        }
        else
        {
                printf("tan(%0.2lf) = %0.15lf\n", degress, expression);
        }

        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-22 09:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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