0

This is my program in C:

  #include<stdio.h>
  #include<math.h>
  int main()
  {   int x, y;
    printf("Enter the cartesian coordinates to be converted into respective polar coordinates");
    scanf(" %d %d", &x, &y );
    float r = sqrt(pow(x,2) + pow(y,2));
    float omega = atan(y/x);
    printf("The required polar coordinates are: (%f, %f)", r, omega);
    return 0;
}

Following input is made:

5 12

And I get:

The required polar coordinates are: (13.000000, 1.107149)

I think the output is only half correct.

I expected, if unit is radian, the output must be:

The required polar coordinates are: (13.000000, 0.3944444)

But the output comes out to be:

The required polar coordinates are: (13.000000, 1.107149)
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 3
    `sqrt(pow(x,2) + pow(y,2))` Nobody ever remembers [`hypot()`](https://en.cppreference.com/w/c/numeric/math/hypot). Or [`atan2()`](https://en.cppreference.com/w/c/numeric/math/atan2)... – Shawn Jun 18 '23 at 07:25
  • 3
    What is `12/5` in C? – Shawn Jun 18 '23 at 07:27
  • Anyways, why do you think it should be 0.3944444 radians? – Shawn Jun 18 '23 at 07:31
  • 1
    `atan((float)y/x);` will avoid the integer division issue and give (13.000000, 1.176005) as a result. Your expectations about the correct result may be incorrect. – Retired Ninja Jun 18 '23 at 07:52
  • If you reverse the coordinates to 12, 5 you will get what you expected `(13,0.394791119699762)` – Retired Ninja Jun 18 '23 at 20:23

0 Answers0