pta6-1 直角坐标转极坐标

6-1 直角坐标转极坐标

请编写函数,将直角坐标 ( x,y ) 转换为极坐标 ( r,θ )。

函数原型
 

void ToPolar(double *r, double *theta, double x, double y);

说明:r 和 theta 分别为指示极径和极角(弧度)的指针,x 和 y 分别为横坐标和纵坐标。

裁判程序
 

#include <stdio.h> #include <math.h> void ToPolar(double *r, double *theta, double x, double y); int main() { double x, y, r, theta; scanf("( %lg, %lg )", &x, &y); ToPolar(&r, &theta, x, y); printf("( %.10g, %.10g )\n", r, theta); return 0; } /* 你提交的程序将被嵌在这里 */

输入样例1
( -1.29903810567665797, 0.75 )

输出样例1
( 1.5, 2.617993878 )

输入样例2
( -2, -3.4641016151377546 )

输出样例2
( 4, -2.094395102 )
void ToPolar(double *r, double *theta, double x, double y){
    
    *r=sqrt(x*x+y*y);
    *theta=atan2(y,x);
}

 

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值