Answer to Question #341394 in C++ for Nia

Question #341394

Write a program that reads in the radius of a circle and prints the circle's diameter,




circumference, and area. Use the constant value 3.14159 for p. Do all calculations in




output statements.

1
Expert's answer
2022-05-15T16:59:17-0400


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
//Implement a function that draw circle
void DrawCircle(int circle_radius)
{
  for (int i = 0; i <= 2*circle_radius; i++)
{
    for (int j = 0; j <= 2*circle_radius; j++)
    {
         float distance_to_centre = sqrt((i - circle_radius)*(i - circle_radius) + (j - circle_radius)*(j - circle_radius));
        if (distance_to_centre > circle_radius-0.5 && distance_to_centre < circle_radius+0.5)
        {
             cout << "*";
        }
        else
        {
             cout << " ";
        }
    }
    cout << endl;
}


}
int main() {
  int rad;
  cout<<"Please input radius :";
  cin>>rad;
  cout<<"Diametr: "<<rad*2<<endl;
  cout<<"S="<<(M_PI*rad*rad)<<endl;  
  cout<<endl;
  DrawCircle(rad);
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS