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.
#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;
}
Comments
Leave a comment