这是根据C语言趣味设计编程边学写,边做的一些归纳总结。
1、对称型的曲线图绘制
主要利用对称性,减少一半的工作量
比如正余弦曲线,对称函数曲线等
例子:
余弦0~360
intm,x;
for(double y=1;y>-1;y-=0.1)
{
m=acos(y)*10;
for(x=1;x<m;x++)
cout<<" ";
cout<<"*";
for(;x<62-m;x++)
cout<<" ";
cout<<"*"<<endl;
}
//62根据acos(-1)*10=31.4...得来。
0~360的正弦曲线图画法如下:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double y;
int x,m;
for( y=1;y>0;y-=0.1)
{
m=asin(y)*10;
for(x=1;x<m;x++)
cout<<" ";
cout<<"*";
for(;x<31-m;x++)
cout<<" ";
cout<<"*"<<endl;
}
for( y=0;y>-1;y-=0.1)
{
m=-(asin(y)*10);
for(x=1;x<32+m;x++)
cout<<" ";
cout<<"*";
for(x=1;x<=32-2*m;x++)
cout<<" ";
cout<<"*"<<endl;
}
return 0;
}
更深一步,同时绘制sin和cos函数曲线:
#include <iostream> #include <cmath>
using namespace std;
int main()
{
int x,m,n;
for(double y=1;y>=-1;y-=0.1)
{
m=acos(y)*10;
n=asin(y)*10;
for(x=0;x<=62;x++)
{
if((x==m&&x==n)||(x==62-m&&x==32-n))
cout<<"+";
else if(x==m||x==62-m)
cout<<"*";
else if(x==n||x==32-n||x==62+n)
cout<<"+";
else
cout<<" ";
} cout<<endl; } return 0; }
画圆形程序:
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++)cout<<" ";cout<<"*";for(;x<30+m;x++)cout<<" ";cout<<"*"<<endl;}
本章完
&spm=1001.2101.3001.5002&articleId=38602511&d=1&t=3&u=993bbb85b30f4eceacbc61e847d8dcc8)
1673

被折叠的 条评论
为什么被折叠?



