余弦函数与直线
#include <stdio.h>
#include <math.h>
int main()
{
double y;
int x,m,n,yy;
for(yy=0;yy<=20;yy++)
{
y=0.1*yy;
m=acos(1-y)*10;
n=45*(y-1)+31;
for(x=0;x<=62;x++)
if(x==m&&x==n)printf("+");
else if (x==n)printf("+");
else if (x==m||x==62-m)printf("*");
else printf(" ");
printf("\n");
}
}
运行结果如下:
圆形
include <stdio.h>
#include <math.h>
int main()
{
double y;
int x,m;
for(y=10;y>=-10;y--)
{
m=2.5*sqrt(100-y*y);
for(x=1;x<30-m;x++)printf(" ");
printf("*");
for(;x<30+m;x++)printf(" ");
printf("*\n");
}
}
运行结果如下: