The polar coordinates r and 9 of a point (x, y) in the plane can be computed as follows: √x² + y² 0= { T= acos(r/r) -acos(x/r) 0 if r> 0 and y>0 if r> 0 and y≤0 ifr=0 Write a program which uses a function called polar() to compute the polar coordinates of a point. Your program must consist of a main program and a function called polar. The function polar () takes the r and y coordinates of a point as arguments and computes the polar coordinates (r, 0). The main program opens the output file polarout.txt for appending (mode="a"), reads the (x, y) coordinates from the keyboard, calls polar (), and then writes both the (x, y) coordinates and the corresponding (r, 0) polar coordinates to the output file. The first (and subsequent) lines of your output should look like: The polar coordinates of (2.0000, 2.0000) are r = 2.8284 and theta = 0.7854 For marking purposes run your program 4 times with (x, y) as follows: (2,2), (1,-1), (0,1) and (3,-1).

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section: Chapter Questions
Problem 1PP
icon
Related questions
Question
Plz solve the question using c programming without changing or adding any other library other than the library # include < stdio.h >, the second photo is a sample of how the coding should look like
#include<stdio.h>
#include<math.h>
float f(float x);
float df (float x):
void newton (float x1, float tol, float* add_root, int" add_iter);
int main(void) {
float x1, tol, root;
int iter;
FILE" fout = fopen("rootsout.txt", "a");
printf("Enter the starting guess and the desired tolerance: ");
scanf("%f%f", 8x1, Stol);
newton (x1, tol, Broot,&iter);
fprintf(fout, "After %d iterations the estimated root near XF is: f\n", iter, x1, root);
fclose(fout);
return;
float (float x){
float yi
y = sin(x)-2.0*exp(-x);
return y;
float df (float x){
float yi
y = cos(x)+2.€*exp(-x);
return y;
}
}
void newton (float x1, float tol, float" add_root, int* add_iter){
float x2;
int iter=;
while(1){
x2 = x1 *(x1)/df(x1);
if (fabs (x2-x1)<tol){
break;
}
x2=x2;
"add_root = x2;
add_iter = iter;
return;
Transcribed Image Text:#include<stdio.h> #include<math.h> float f(float x); float df (float x): void newton (float x1, float tol, float* add_root, int" add_iter); int main(void) { float x1, tol, root; int iter; FILE" fout = fopen("rootsout.txt", "a"); printf("Enter the starting guess and the desired tolerance: "); scanf("%f%f", 8x1, Stol); newton (x1, tol, Broot,&iter); fprintf(fout, "After %d iterations the estimated root near XF is: f\n", iter, x1, root); fclose(fout); return; float (float x){ float yi y = sin(x)-2.0*exp(-x); return y; float df (float x){ float yi y = cos(x)+2.€*exp(-x); return y; } } void newton (float x1, float tol, float" add_root, int* add_iter){ float x2; int iter=; while(1){ x2 = x1 *(x1)/df(x1); if (fabs (x2-x1)<tol){ break; } x2=x2; "add_root = x2; add_iter = iter; return;
The polar coordinates r and 0 of a point (x, y) in the plane can be computed as follows:
√x² + y²
72
0-
T=
acos(x/r) if r> 0 and y > 0
-acos(x/r) if r > 0 and y ≤ 0
0
Write a program which uses a function called polar() to compute the polar coordinates of
a point. Your program must consist of a main program and a function called polar. The
function polar() takes the r and y coordinates of a point as arguments and computes the
polar coordinates (r, 0). The main program opens the output file polarout.txt for appending
(mode "a"), reads the (x, y) coordinates from the keyboard, calls polar (), and then writes
both the (x, y) coordinates and the corresponding (7, 8) polar coordinates to the output file.
The first (and subsequent) lines of your output should look like:
The polar coordinates of (2.0000, 2.0000) are = 2.8284 and theta = 0.7854
1
For marking purposes run your program 4 times with (x, y) as follows: (2,2), (1,-1),
(0,1) and (3,-1).
Transcribed Image Text:The polar coordinates r and 0 of a point (x, y) in the plane can be computed as follows: √x² + y² 72 0- T= acos(x/r) if r> 0 and y > 0 -acos(x/r) if r > 0 and y ≤ 0 0 Write a program which uses a function called polar() to compute the polar coordinates of a point. Your program must consist of a main program and a function called polar. The function polar() takes the r and y coordinates of a point as arguments and computes the polar coordinates (r, 0). The main program opens the output file polarout.txt for appending (mode "a"), reads the (x, y) coordinates from the keyboard, calls polar (), and then writes both the (x, y) coordinates and the corresponding (7, 8) polar coordinates to the output file. The first (and subsequent) lines of your output should look like: The polar coordinates of (2.0000, 2.0000) are = 2.8284 and theta = 0.7854 1 For marking purposes run your program 4 times with (x, y) as follows: (2,2), (1,-1), (0,1) and (3,-1).
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr