编程语言
首页 > 编程语言> > c++圆形

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;
}

标签:int,double,void,c++,圆形,print,circle,include
来源: https://blog.csdn.net/LongXingLuoLuo/article/details/120404518