C Program To Convert Polar To Cartesian Co-ordinates

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

  1.    
  2. #include < stdio.h >  
  3. #include < math.h >  
  4.   
  5. int main()  
  6. {  
  7.     float x, y, r, theta;  
  8.     const float PI = 3.141592;  
  9.   
  10.     printf("Enter Polar Co-ordinates(r, theta)\n");  
  11.     scanf("%f%f", &r, &theta);  
  12.   
  13.     /* Convert angle from Degree To Radian */    theta = theta * (PI / 180.0);   
  14.   
  15.     x = r * cos(theta);  
  16.     y = r * sin(theta);  
  17.   
  18.     printf("Cartesian Co-ordinates (x, y) = (%f, %f)\n", x, y);  
  19.   
  20.     return 0;  
  21. }  

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 Link: https://www.youtube.com/watch?v=XCz3CDUsC9o [Watch the Video In Full Screen.]


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

Print All Trigonometric Ratios: C Program

If value of an angle is input through the keyboard, write a c program to print all its Trigonometric Ratios.

Formula To Convert Degree To Radian

radian = degree * (PI / 180.0);
where PI = 3.14159; (constant value)

Logic to Print all Trigonometric Ratios

First we ask the user to input angle of a Triangle in degrees. Next we convert angel from degrees to radian.

Next we include math.h header file and use methods present in it to get:
sin()
cos()
tan()

To get cosec() = 1 / sin();
To get sec() = 1 / cos();
To get cot() = 1 / tan();

tan() value can also be obtained using sin() / cos();
cot() value can also be obtained using cos() / sin();

Source Code: Print All Trigonometric Ratios: C Program

  1.    
  2. #include < stdio.h >  
  3. #include < math.h >  
  4.   
  5. int main()  
  6. {  
  7.     float degree, radian;  
  8.     const float PI = 3.14159;  
  9.   
  10.     printf("Enter angle in degree\n");  
  11.     scanf("%f", °ree);  
  12.   
  13.     radian = degree * (PI / 180.0);  
  14.   
  15.     printf("Sin(%f) = %f\n", degree, sin(radian));  
  16.     printf("Cos(%f) = %f\n", degree, cos(radian));  
  17.     printf("Tan(%f) = %f\n", degree, tan(radian));  
  18.     printf("Cosec(%f) = %f\n", degree, 1/sin(radian));  
  19.     printf("Sec(%f) = %f\n", degree, 1/cos(radian));  
  20.     printf("Cot(%f) = %f\n", degree, 1/tan(radian));  
  21.   
  22.     return 0;  
  23. }  

Output 1
Enter angle in degree
30
Sin(30.000000) = 0.500000
Cos(30.000000) = 0.866026
Tan(30.000000) = 0.577350
Cosec(30.000000) = 2.000001
Sec(30.000000) = 1.154700
Cot(30.000000) = 1.732052

Output 2
Enter angle in degree
45
Sin(45.000000) = 0.707106
Cos(45.000000) = 0.707107
Tan(45.000000) = 0.999999
Cosec(45.000000) = 1.414214
Sec(45.000000) = 1.414213
Cot(45.000000) = 1.000001

Print All Trigonometric Ratios: C Program



YouTube Link: https://www.youtube.com/watch?v=-FMdZ456FUA [Watch the Video In Full Screen.]


Tan and Cot

  1. printf("Tan(%f) = %f\n", degree, sin(radian)/cos(radian));  
  2. printf("Cot(%f) = %f\n", degree, cos(radian)/sin(radian));  

OR

  1. printf("Tan(%f) = %f\n", degree, tan(radian));  
  2. printf("Cot(%f) = %f\n", degree, 1/tan(radian));  

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