Write a C program to receive Polar co-ordinates(r, θ) and convert them into Cartesian co-ordinates(x, y). Ask the user to enter theta(θ) value in degrees.
Related Read:
C Program To Convert Cartesian To Polar Co-ordinates
Formula To Convert Polar To Cartesian Co-ordinates
x = r * cos(θ);
y = r * sin(θ);
where x and y are Cartesian co-ordinates. r and θ are polar co-ordinates.
Formula To Convert Degree To Radian
radian = degree * (PI/180.0);
where PI is 3.141592
Source Code: Convert Polar To Cartesian Co-ordinates: C Program
#include < stdio.h > #include < math.h > int main() { float x, y, r, theta; const float PI = 3.141592; printf("Enter Polar Co-ordinates(r, theta)\n"); scanf("%f%f", &r, &theta); /* Convert angle from Degree To Radian */ theta = theta * (PI / 180.0); x = r * cos(theta); y = r * sin(theta); printf("Cartesian Co-ordinates (x, y) = (%f, %f)\n", x, y); return 0; }
Output:
Enter Polar Co-ordinates(r, theta)
5.01
53.131
Cartesian Co-ordinates (x, y) = (3.005938, 4.008047)
Convert Polar To Cartesian Co-ordinates: C Program
[youtube https://www.youtube.com/watch?v=XCz3CDUsC9o]
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert