Bootstrap

C语言-常用算法-28

题目:

极坐标用向量的莫(即向量的长度)和向量相对x轴逆时针旋转的角度来描述该变量。直角坐标用向量的x轴和y轴的坐标来描述该向量。编写一个程序,读取向量的模和角度,然后显示x轴和y轴的坐标

X = r * cos A y = r * sin A

源代码:

#include <stdio.h>
#include <math.h>
#define PI 3.14
typedef struct{
    double length;
    double angle;
}polar; //向量模板,包括向量模长和角度
typedef struct{
    double x;
    double y;
}rectangular;
rectangular p_to_t(polar pc);
int main()
{
    polar pc;
    scanf("%lf %lf",&pc.length,&pc.angle);
    pc.angle = pc.angle * (PI / 180.0);  //角度转换为弧度
    rectangular r = p_to_t(pc);
    printf("%lf %lf\n",r.x,r.y);
}
rectangular p_to_t(polar pc)
{
    rectangular rect;
    rect.x = pc.length * cos(pc.angle);
    rect.y = pc.length * sin(pc.angle);
    return rect;
}

演示效果:


如果朋友你感觉文章的内容对你有帮助,可以点赞关注文章和专栏以及关注我哈,嘿嘿嘿我会定期更新文章的,谢谢朋友你的支持哈

;