作为一个刚刚学习C语言十来天的小白,看了c语言趣味一百例的前两道,还是很有兴趣的,所以就进行对第一问的尝试
cos图像的程序如下
#include <stdio.h>
#include <math.h>
int main()
{
double y;
int x,m;
for(y = 1;y >= -1;y -= 0.2) // 函数的y轴图像,从1到-1,每隔0.2打印一次图像
{
m = acos(y) * 5; // 使用反函数arccos计算x,y的关系,乘5为放大倍数
for(x = 1;x < m;x++) // 打印函数的一半图像
{
printf(" ");
}
printf("*");
for(;x < 31 - m;x++) // 打印另一半图像
{
printf(" ");
}
printf("*\n");
}
return 0;
}
运行图像如下<