问题及代码:
/*
* Copyright (c) 2018, dongsheng.
* All rights reserved.
* 文件名称: 20180905.c
* 作 者: zhadongsheng
* 完成日期: 2018年9月5日
* 版 本 号: v1.0
* 问题描述: 写一个程序把极坐标(r,θ) (θ之单位为度)转换为直角坐标( X,Y);
* 算法描述: x=r*cosθ; y=r*sinθ;
* 输入描述: 输入r与theta;
* 程序输出: (x,y).
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define pi 3.1416 //用符号常量处理
int main()
{
double r,theta,x,y;
scanf("%lf %lf",&r,&theta);
x=r*cos(theta/180*pi);//注意cos需要弧度作为参数。
y=r*sin(theta/180*pi);
printf("(%f,%f)\n",x,y);
return 0;
}
运行结果:
知识点总结:
cos与sin 在运算过程中要转化成弧度参数作为计算
可以把π定义为符号常量写成#include pi 3.1416 不要写成pi=3.1416.
学习心得:
不断学习会进步的。