读书人

用c语言 打印圆形,该怎么处理

发布时间: 2012-02-21 16:26:23 作者: rapoo

用c语言 打印圆形

如上图的圆形,,怎么用C语言实现,,,要求在 X^2+Y^2=R^2的范围内,,,
大虾们,,给以下思路和 代码,,,

[解决办法]
#include <stdio.h>
#include <stdlib.h>


const int R=16;

int main()
{
for(int x=0;x<=2*R;++x)
{
for(int y=0;y<=2*R;++y)
{
if((x-R)*(x-R)+(y-R)*(y-R)<=R*R)
printf(" *");//打印空格+‘*”
else
printf(" ");//打印两空格
}
printf("\n");
}
system("pause");
return 0;
}

[解决办法]
右边

C/C++ code
 
#include <iostream>

using namespace std;
const unsigned int R=35;

int main()
{
for (int x=0;x <=2*R;++x)
{
int pr=(x-R)*(x-R);
for (int y=0;y <=2*R;++y)
{
if (pr+(y-R)*(y-R) <=R*R)
cout < <" ";
else
cout < <"*";
}
cout < <endl;
}

return 0;
}

[解决办法]
#include <stdio.h>
#include <stdlib.h>


const int R=16;

int main()
{
for(int x=0;x<=2*R;++x)
{
for(int y=0;y<=2*R;++y)
{
if((x-R)*(x-R)+(y-R)*(y-R)>R*R)
printf(" *");
else
printf(" ");
}
printf("\n");
}
system("pause");
return 0;
}

读书人网 >C语言

热点推荐