Please answer the following question in C program only. Write two C functions na
ID: 3923523 • Letter: P
Question
Please answer the following question in C program only.
Write two C functions named dist () and angle (). respectively, to be used in convening the rectangular (x, y)coordinates of a point into polar form. That is given an x and y position on a Cartesian coordinate system, as illustrated in Figure 6.11 the dist () function must Calculate and return the distance from the origin x and the angle () function must calculate and return the angle from the x-axis 0 specified by point The value of x and theta are referred to as the point polar coordinates Use the relationships that r = Squareroot x^2 + y^2 theta tan^4 (y/x), x notequalto 0 Correspondence between polar (distance, r and angle. theta) and Cartesian (x, y) coordinatesExplanation / Answer
// C code to determine distance and angle of point from origin
#include <stdio.h>
#include <math.h>
double dist(double x, double y)
{
double distance = sqrt(x*x + y*y);
return distance;
}
double angle(double x, double y)
{
double result = atan2(y,x);
return result;
}
int main()
{
double x;
double y;
printf("Enter x co-ordinate: ");
scanf("%lf",&x);
printf("Enter x co-ordinate: ");
scanf("%lf",&y);
printf("Distance from origin: %lf " ,dist(x,y));
printf("Angle from origin: %lf degree " ,(angle(x,y)*180*7)/22);
return 0;
}
/*
output:
Enter x co-ordinate: 1
Enter x co-ordinate: 1
Distance from origin: 1.414214
Angle from origin: 44.981895 degree
*/