#include <stdio.h> #include <math.h> main() { double y; int x,m,n,yy; for(yy=0;yy<=20;yy++) //对于每一个y坐标进行计算并在一行中打印图形 { //y:屏幕行方向坐标 y=0.1*yy; //m:cos(x)曲线上y点对应的屏幕列坐标 m=acos(1-y)*10; //n:直线上y点对应的列坐标 n=45*(y-1)+31; //x:屏幕列方向坐标 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"); } } /*运行结果如下: ----------------------------------------------------------------------------------------------- * * * * * * + * * + * * + * * * + * * + * * + * * + * * + * * + * * + * * + * * + * * + * * + * * + * * * * * Press any key to continue ----------------------------------------------------------------------------------------------- */ 思考题:如何实现sin(x)与cos(x)曲线的同时显示? 解答:#include<stdio.h> #include<math.h> #define PAI 32 #define AMP 10 int main(void) { double y; int x,m,n,layer; for(layer=0;layer<=20;++layer) { y=0.1*layer; m=(int)(acos(1-y)*AMP); n=(int)(asin(1-y)*AMP); for(x=0;x<2*PAI;++x) { if((x==m && x==n)||(x==2*PAI-m && x==PAI-n)) printf("+"); //cross pointer else if(x==n||x==PAI-n||x==n+2*PAI) printf("+"); //on sin(x) else if(x==m||x==2*PAI-m) printf("*"); //on cos(x) else printf(" "); //blank } printf("/n");//next line } return 0; } /* --------------------------------------------------------------------------------------- * + + * + + * * + + * + + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * * + * + * + * + * + * + * + * + * + * + * + * + * + * + * *+ + * * + + * * + + Process returned 0 (0x0) execution time : 0.109 s Press any key to continue. --------------------------------------------------------------------------------------- */