Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define PI 3.141592
- int c = 0;
- void c2p();
- void p2c();
- struct complexcart
- {
- double real;
- double imaginary;
- } point1, point2, point3, cart_point4, cart_point5, cart_point6, *p;
- struct complexpol
- {
- double radius;
- double angle;
- } point4, point5, point6, pol_point1, pol_point2, pol_point3, *q;
- void main(){
- struct complexcart point1 = {3, 0.8};
- struct complexcart point2 = {0, log10(4)};
- struct complexcart point3 = {45.245, 0.235};
- struct complexpol point4 = {3, (PI/17)};
- struct complexpol point5 = {4, (PI/9)};
- struct complexpol point6 = {1, (PI/12)};
- while (c < 6)
- {
- if (c == 0)
- {
- struct complexcart *p = &point1;
- c2p();
- c++;
- }
- if (c == 1)
- {
- struct complexcart *p = &point2;
- c2p();
- c++;
- }
- if (c == 2)
- {
- struct complexcart *p = &point3;
- c2p();
- c++;
- }
- if (c == 3)
- {
- struct complexpol *q = &point4;
- p2c();
- c++;
- }
- if (c == 4)
- {
- struct complexpol *q = &point5;
- p2c();
- c++;
- }
- if (c == 5)
- {
- struct complexpol *q = &point6;
- p2c();
- c++;
- }
- }
- printf("Converted from cartesian to polar: n");
- printf("%.0lf + %.1lfi -> %lf * e^(%lfi) n", point1.real, point1.imaginary, pol_point1.radius, pol_point1.angle);
- printf("%.0lf + %lfi -> %lf * e^(%lfi) n", point2.real, point2.imaginary, pol_point2.radius, pol_point2.angle);
- printf("%.3lf + %.3lfi -> %lf * e^(%lfi) n", point3.real, point3.imaginary, pol_point3.radius, pol_point3.angle);
- printf("Converted from polar to cartesian: n");
- printf("%.0lf * e^(%lfi) -> %lf + %lfi n", point4.radius, point4.angle, cart_point4.real, cart_point4.imaginary);
- printf("%.0lf * e^(%lfi) -> %lf + %lfi n", point5.radius, point5.angle, cart_point5.real, cart_point5.imaginary);
- printf("%.0lf * e^(%lfi) -> %lf + %lfi n", point6.radius, point6.angle, cart_point6.real, cart_point6.imaginary);
- }
- void c2p(){
- if (c == 0)
- {
- p = &point1;
- struct complexpol polar_point1 = {sqrt(pow((*p).real, 2) + pow((*p).imaginary, 2)), atan((*p).imaginary/(*p).real)};
- }
- if (c == 1)
- {
- p = &point2;
- struct complexpol polar_point2 = {sqrt(pow((*p).real, 2) + pow((*p).imaginary, 2)), atan((*p).imaginary/(*p).real)};
- }
- if (c == 2)
- {
- p = &point3;
- struct complexpol polar_point3 = {sqrt(pow((*p).real, 2) + pow((*p).imaginary, 2)), atan((*p).imaginary/(*p).real)};
- }
- }
- void p2c(){
- if (c == 3)
- {
- q = &point4;
- struct complexcart cart_point4 = {(*q).radius * cos((*q).angle), (*q).radius * sin((*q).angle)};
- }
- if (c == 4)
- {
- q = &point5;
- struct complexcart cart_point5 = {(*q).radius * cos((*q).angle), (*q).radius * sin((*q).angle)};
- }
- if (c == 5)
- {
- q = &point6;
- struct complexcart cart_point6 = {(*q).radius * cos((*q).angle), (*q).radius * sin((*q).angle)};
- }
- }
Add Comment
Please, Sign In to add comment