思路
模拟题意,运用两点间距离公式判断当前点到圆心的距离与圆半径的关系即可。
两点间距离公式:设点 ,,则 。
Code
#include <bits/stdc++.h>
using namespace std;
int x,y,r,n;
signed main() {
cin>>x>>y>>r>>n;
for (int i=-n;i<=n;i++) {
for (int j=-n;j<=n;j++) {
if (sqrt((i-x)*(i-x)+(j-y)*(j-y))<=r) cout<<"# ";
else cout<<". ";
}
cout<<endl;
}
return 0;
}