c++圆形

/*打印圆形*/
#include <iostream>
#include <math.h>
using namespace std;
void print_circle(int);
double D(int, int);
int main()
{
	int R;/*变量半径*/
	cout << "请输入半径:" << endl;
	cin >> R;
	print_circle(R);
}
void print_circle(int R)
{
	double a = 0, b = 0;/*a是列数,b是行数*/
	for (b = 0; b <= (2 * R); b++)
	{
		for (a = 0; a <= (2 * R); a += 0.5)
		{
			if (a >= (R - D(b, R)) && a <= (R + D(b, R)))
				cout << "*";
			else cout << " ";
		}
		cout << '\n';
	}
}
double D(int b, int R)
{
	double a;
	a = sqrt((2 * R - b) * b);
	return a;
}

上一篇:根据下图实现类。在CylinderTest类中创建Cylinder类的对象,设置圆柱的底面半径和高,并输出圆柱的体积,继承性


下一篇:P322 static应用举例