Calculating a rectangle
Wed Aug 23 2023 00:08:20 GMT+0000 (Coordinated Universal Time)
Saved by
@Codes
// Online C compiler to run C program online
#include <stdio.h>
#include <math.h>
struct tangle{
float x,y;
};
struct polar{
float r, theta;
};
struct polar convert(struct tangle rect){
struct polar pol;
if(rect.x==0 && rect.y==0){
pol.r = pol.theta = 0;
}
else{
pol.r=sqrt(rect.x*rect.x + rect.y*rect.y);
double ans = (rect.y,rect.x);
pol.theta = atan(ans);
}
return pol;
}
int main() {
struct tangle rect = {2,1};
struct polar p;
p = convert(rect);
printf("%.2f %.2f",p.r,p.theta);
return 0;
}
content_copyCOPY
Comments