Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have my code in C++ can someone help me convert this into C code #include #inc

ID: 3606646 • Letter: I

Question

I have my code in C++ can someone help me convert this into C code

#include #include #include #include using namespace std; #define M_PI 3.14 int main() { double r; cout << "Please enter radius value r: "; cin >> r; while (r <=0) { cout << "Please enter a valid positive value of r: "; cin >> r; } double Inputerror; cout << "Please enter a starting acceptable error: "; cin >> Inputerror; while (Inputerror <0 || Inputerror > 0.25 * r) { cout << "Please enter a valid starting acceptable error: "; cin >> Inputerror; } cout << std::fixed << setprecision(2) << "M_PI*r*r: " << M_PI*r*r << endl; //Inscribed method: cout << "Method one: "; int n = 3; double angle = 360 / n; double area = n * 12 * r*r*sin((angle*M_PI) / 180); //area=n×12r2sina vector methodOne; methodOne.push_back(area); double error = area - M_PI*r*r; int k = 1; while (error > Inputerror) { n++; area = n * 12 * r*r*sin((angle*M_PI) / 180); error = area - M_PI*r*r; cout << "Error :" << std::fixed << setprecision(4) << error << endl; methodOne.push_back(area); error = error / pow(10, k++); // error = error/10 for each iteration } int i = 0; for (auto it = methodOne.begin(); it != methodOne.end(); it++) { cout << i++ + 1 << std::fixed << setprecision(2) << " area: " << *it << endl; } //Circumscribed method cout << "Method Two: "; n = 3; angle = 360 / n; double a = (angle*M_PI) / 180; area = n * 12 * r*cos(a/2)*2*sin(a); //area=n×12×rcos(a2)2×sina vector methodTwo; methodTwo.push_back(area); error = area - M_PI*r*r; k = 0; while (error > Inputerror) { n++; area = n * 12 * r*cos(a / 2) * 2 * sin(a); error = area - M_PI*r*r; methodTwo.push_back(area); cout << "Error :" << std::fixed << setprecision(4) << error << endl; error = error / pow(10, k++); // error = error/10 for each iteration } i = 0; for (auto it = methodTwo.begin(); it != methodTwo.end(); it++) { cout << i++ + 1 << std::fixed << setprecision(2) << " area: " << *it << endl; } //Middle Rectangles method cout << "Method Three: "; n = 1; double w = r / n;//width of the rectangles as w=r / n //area = i = 1nw×r2 - w×i - 122 area = 0; for (int i = 1; i<=n; i++) { area += n*w*r*r - w*i - 122; } vector methodThree; methodThree.push_back(area); error = area - M_PI*r*r; while (error > Inputerror) { n++; area = 0; for (int i = 1; i <= n; i++) { area += n*w*r*r - w*i - 122; } error = area - M_PI*r*r; methodThree.push_back(area); cout << "Error :" << std::fixed << setprecision(4) << error << endl; error = error / pow(10, k++); // error = error/10 for each iteration } i = 0; for (auto it = methodThree.begin(); it != methodThree.end(); it++) { cout << i++ + 1 << std::fixed << setprecision(2) << " area: " << *it << endl; } system("pause"); return 0; }

Explanation / Answer

#include <stdio.h>
#include <math.h>
#include


#define M_PI 3.14
int main()
{
double r;
printf("Please enter radius value r: ");
scanf("%g",r);
while (r <=0)
{
printf("Please enter a valid positive value of r: ");
scanf("%g",r);
}
double Inputerror;
printf("Please enter a starting acceptable error: ");
scanf("%g",Inputerror);
while (Inputerror <0 || Inputerror > 0.25 * r)
{
printf("Please enter a valid starting acceptable error: ");
scanf("%g",Inputerror);
}
printf("%g",setprecision(2));
printf("M_PI*r*r: %g ", M_PI*r*r);
//Inscribed method:
printf("Method one: ");
int n = 3;
double angle = 360 / n;
double area = n * 12 * r*r*sin((angle*M_PI) / 180);
//area=n×12r2sina
vector methodOne;
methodOne.push_back(area);
double error = area - M_PI*r*r;
int k = 1;
while (error > Inputerror)
{
n++;
area = n * 12 * r*r*sin((angle*M_PI) / 180);
error = area - M_PI*r*r;
printf("Error :");
printf("%g",setprecision(4));
printf("%g ",error);
methodOne.push_back(area);
error = error / pow(10, k++);
// error = error/10 for each iteration
  
}
int i = 0;
for (auto it = methodOne.begin(); it != methodOne.end(); it++)
{
printf("%g", i++ + 1);
printf("%g",setprecision(2));
printf(" area: ");
printf("%g ", *it);
}
//Circumscribed method
printf("%g",Method Two: );
n = 3;
angle = 360 / n;
double a = (angle*M_PI) / 180;
area = n * 12 * r*cos(a/2)*2*sin(a);
//area=n×12×rcos(a2)2×sina
vector methodTwo;
methodTwo.push_back(area);
error = area - M_PI*r*r;
k = 0;
while (error > Inputerror) {
n++;
area = n * 12 * r*cos(a / 2) * 2 * sin(a);
error = area - M_PI*r*r;
methodTwo.push_back(area);
printf("Error :");
printf("%g ",setprecision(4));
printf("%g", error);
error = error / pow(10, k++);
// error = error/10 for each iteration
  
}
i = 0;
for (auto it = methodTwo.begin(); it != methodTwo.end(); it++)
{
printf("%g", i++ + 1);
printf("%g",setprecision(2));
printf(" area: ");
printf("%g ", *it);
}
//Middle Rectangles method
printf("Method Three: ");
n = 1;
double w = r / n;
//width of the rectangles as w=r / n //area = i = 1nw×r2 - w×i - 122
area = 0;
for (int i = 1; i<=n; i++)
{
area += n*w*r*r - w*i - 122;
}
vector methodThree;
methodThree.push_back(area);
error = area - M_PI*r*r;
while (error > Inputerror)
{
n++;
area = 0;
for (int i = 1; i <= n; i++)
{
area += n*w*r*r - w*i - 122;
  
}
error = area - M_PI*r*r;
methodThree.push_back(area);
printf("Error :");
printf("%g ",setprecision(4));
printf("%g", error);
error = error / pow(10, k++);
// error = error/10 for each iteration
}
i = 0;
for (auto it = methodThree.begin(); it != methodThree.end(); it++)
{
printf("%g", i++ + 1);
printf("%g",setprecision(2));
printf(" area: ");
printf("%g ", *it);
}
system("pause");
return 0;
  
}