Guest User

Untitled

a guest
Nov 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define PI 3.141592
  4.  
  5. int c = 0;
  6.  
  7. void c2p();
  8. void p2c();
  9.  
  10. struct complexcart
  11. {
  12. double real;
  13. double imaginary;
  14. } point1, point2, point3, cart_point4, cart_point5, cart_point6, *p;
  15.  
  16. struct complexpol
  17. {
  18. double radius;
  19. double angle;
  20. } point4, point5, point6, pol_point1, pol_point2, pol_point3, *q;
  21.  
  22. void main(){
  23. struct complexcart point1 = {3, 0.8};
  24. struct complexcart point2 = {0, log10(4)};
  25. struct complexcart point3 = {45.245, 0.235};
  26.  
  27. struct complexpol point4 = {3, (PI/17)};
  28. struct complexpol point5 = {4, (PI/9)};
  29. struct complexpol point6 = {1, (PI/12)};
  30.  
  31.  
  32. while (c < 6)
  33. {
  34. if (c == 0)
  35. {
  36. struct complexcart *p = &point1;
  37. c2p();
  38. c++;
  39. }
  40. if (c == 1)
  41. {
  42. struct complexcart *p = &point2;
  43. c2p();
  44. c++;
  45. }
  46. if (c == 2)
  47. {
  48. struct complexcart *p = &point3;
  49. c2p();
  50. c++;
  51. }
  52. if (c == 3)
  53. {
  54. struct complexpol *q = &point4;
  55. p2c();
  56. c++;
  57. }
  58. if (c == 4)
  59. {
  60. struct complexpol *q = &point5;
  61. p2c();
  62. c++;
  63. }
  64. if (c == 5)
  65. {
  66. struct complexpol *q = &point6;
  67. p2c();
  68. c++;
  69. }
  70. }
  71. printf("Converted from cartesian to polar: n");
  72. printf("%.0lf + %.1lfi -> %lf * e^(%lfi) n", point1.real, point1.imaginary, pol_point1.radius, pol_point1.angle);
  73. printf("%.0lf + %lfi -> %lf * e^(%lfi) n", point2.real, point2.imaginary, pol_point2.radius, pol_point2.angle);
  74. printf("%.3lf + %.3lfi -> %lf * e^(%lfi) n", point3.real, point3.imaginary, pol_point3.radius, pol_point3.angle);
  75.  
  76. printf("Converted from polar to cartesian: n");
  77. printf("%.0lf * e^(%lfi) -> %lf + %lfi n", point4.radius, point4.angle, cart_point4.real, cart_point4.imaginary);
  78. printf("%.0lf * e^(%lfi) -> %lf + %lfi n", point5.radius, point5.angle, cart_point5.real, cart_point5.imaginary);
  79. printf("%.0lf * e^(%lfi) -> %lf + %lfi n", point6.radius, point6.angle, cart_point6.real, cart_point6.imaginary);
  80. }
  81.  
  82. void c2p(){
  83. if (c == 0)
  84. {
  85. p = &point1;
  86. struct complexpol polar_point1 = {sqrt(pow((*p).real, 2) + pow((*p).imaginary, 2)), atan((*p).imaginary/(*p).real)};
  87. }
  88. if (c == 1)
  89. {
  90. p = &point2;
  91. struct complexpol polar_point2 = {sqrt(pow((*p).real, 2) + pow((*p).imaginary, 2)), atan((*p).imaginary/(*p).real)};
  92. }
  93. if (c == 2)
  94. {
  95. p = &point3;
  96. struct complexpol polar_point3 = {sqrt(pow((*p).real, 2) + pow((*p).imaginary, 2)), atan((*p).imaginary/(*p).real)};
  97. }
  98. }
  99.  
  100. void p2c(){
  101. if (c == 3)
  102. {
  103. q = &point4;
  104. struct complexcart cart_point4 = {(*q).radius * cos((*q).angle), (*q).radius * sin((*q).angle)};
  105. }
  106. if (c == 4)
  107. {
  108. q = &point5;
  109. struct complexcart cart_point5 = {(*q).radius * cos((*q).angle), (*q).radius * sin((*q).angle)};
  110. }
  111. if (c == 5)
  112. {
  113. q = &point6;
  114. struct complexcart cart_point6 = {(*q).radius * cos((*q).angle), (*q).radius * sin((*q).angle)};
  115. }
  116. }
Add Comment
Please, Sign In to add comment