zoukankan      html  css  js  c++  java
  • 第 16 章 C 预处理器和 C 库(直角坐标转换极坐标)

     1 /*-------------------------------------
     2     rect_pol.c -- 把直角坐标转换为极坐标
     3 -------------------------------------*/
     4 
     5 #include <stdio.h>
     6 #include <math.h>
     7 
     8 #define RAD_TO_DEG    (180 / (4 * atan(1.0)))
     9 
    10 typedef struct polar_v
    11 {
    12     double magnitude;
    13     double angle;
    14 } Polar_V;
    15 
    16 typedef struct rect_v
    17 {
    18     double x;
    19     double y;
    20 } Rect_V;
    21 
    22 Polar_V rect_to_polar(Rect_V);
    23 
    24 int main()
    25 {
    26     Rect_V input;
    27     Polar_V result;
    28 
    29     puts("Enter x and y coordinates; enter q to quit:");
    30     while (scanf("%lf %lf", &input.x, &input.y) == 2)
    31     {
    32         result = rect_to_polar(input);
    33         printf("magnitude = %0.2f, angle = %0.2f
    ", result.magnitude, result.angle);
    34     }
    35     
    36     return 0;
    37 }
    38 
    39 Polar_V rect_to_polar(Rect_V rv)
    40 {
    41     Polar_V pv;
    42 
    43     pv.magnitude = sqrt(pow(rv.x, 2) + pow(rv.y, 2));
    44     if (pv.magnitude == 0)
    45         pv.angle = 0;
    46     else
    47         pv.angle = RAD_TO_DEG * atan2(rv.y, rv.x);
    48 
    49     return pv;
    50 }
    rect_pol.c

  • 相关阅读:
    jQuery基础及选择器
    JavaScript面向对象
    JavaScript操作DOM
    JavaScript Bom对象
    jquery内容
    jQuery基础
    正则表达式
    表单校验
    使用jQuery操作DOM
    jQuery中的动画
  • 原文地址:https://www.cnblogs.com/web1013/p/9257416.html
Copyright © 2011-2022 走看看