问题及代码:
写一个程序把极坐标(r,θ) (θ之单位为度)转换为直角坐标( X,Y)。转换公式是:
x=r.cosθ
y=r.sinθ
/*
*Copyright(c)2015,优快云学院
*All rights reserved.
*文件名称:main.c
*作 者:Grepie
*完成日期:2015年8月20日
*版 本 号:v1.0
*项目:写一个程序把极坐标(r,θ) (θ之单位为度)转换为直角坐标(X,Y)
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define pi 3.1415926
int main()
{
double r,theta,x,y;
printf("输入极坐标");
scanf("%lf %lf",&r,&theta);
x=r*cos(theta/180*pi);
y=r*sin(theta/180*pi);
printf("转换为直角坐标%lf %lf",x,y);
return 0;
}
运行结果:
小结:定义了常量PI,方便运算