In: Computer Science
Define two C structures, one to represent rectangular coordinates and one to represent polar coordinates. Rewrite the rec_to_polar function to use variables declared using the new structures.
thanks for the question, here is the code in C language, I have created the two structures, however the function rec_to_polar was not shared, I have assumed the function will take in a rectangular struct object and return a polar struct object.
Hope this helps, let me know for any help with any other question.
here is the code.
===============================================================
#include<stdio.h>
#include<math.h>
struct RectangularCordinate{
float x;
float y;
};
struct PolarCordinate{
float radius;
float theta;
};
struct PolarCordinate rect_to_polar(struct RectangularCordinate rect){
float radius = pow(rect.x*rect.x + rect.y*rect.y,0.5);
float angle = atan(rect.y/rect.x);
struct PolarCordinate pol = {radius,angle};
return pol;
}
int main(){
struct RectangularCordinate rect {3,4};
struct PolarCordinate pol = rect_to_polar(rect);
printf("Radius: %.2f\n", pol.radius) ;
printf("Angle: %.2f\n", pol.theta) ;
}
===============================================================