栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言 输出角度所在象限

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言 输出角度所在象限

一、题目

003:编写一个程序,要求输入一个角度的大小(度数),输出该角度所在的象限 。
(书例3.19)

二、代码实现 思路:需要对输入的角度进行处理,化为0-360度之间的角度,特别的与坐标轴重合的单独拎出

代码如下:

//003:编写一个程序,要求输入一个角度的大小(度数),输出该角度所在的象限 
#include
#include
int main()
{
    int intangle;//取整处理后的角度
    float angle;//原始角
    scanf("%f",&angle);
    printf("The given angle is: %f degreesn",angle);
    if((floor(angle)-angle==0)&&(int)angle%90==0)//如果角度是正好与坐标轴重合
    printf("and coincides with the coordinate axis");
    else
    {
    intangle=floor(angle);//不用int取整是因为负数处理会出错,使用向下取整floor()
    if(intangle>=0)
    intangle%=360;//正角度直接对360取余即可
    else
    intangle=360-(-intangle)%360;//负角度化为正角度
    printf("and lies in");
    switch(intangle/90)
    {
        case 0:printf("the first");break;
        case 1:printf("the second");break;
        case 2:printf("the third");break;
        case 3:printf("the forth");break;//switch-case判断
    }
    printf(" quadrantn");
    }
    return 0;
}
运行结果
90.1
The given angle is: 90.099998 degrees
and lies inthe second quadrant
270
The given angle is: 270.000000 degrees
and coincides with the coordinate axis
-90.1
The given angle is: -90.099998 degrees
and lies inthe third quadrant
-180
The given angle is: -180.000000 degrees
and coincides with the coordinate axis
说明一下,floor()函数向下取整,ceil()函数向上取整,math.h
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/857609.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号