屏幕上用“*”显示0-360度的余弦函数cos(x)曲线#include #include int main (){double y;int x,m; for( y = 1; y >= -1; y -= 0.1){m = cos(y)*10;for( x = 1; x < m; x++) printf("");printf("*");for(; x < 62-m; x++)printf("");printf("*\n");}
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 09:19:35
屏幕上用“*”显示0-360度的余弦函数cos(x)曲线#include #include int main (){double y;int x,m; for( y = 1; y >= -1; y -= 0.1){m = cos(y)*10;for( x = 1; x < m; x++) printf("");printf("*");for(; x < 62-m; x++)printf("");printf("*\n");}
屏幕上用“*”显示0-360度的余弦函数cos(x)曲线
#include
#include
int main ()
{
double y;
int x,m;
for( y = 1; y >= -1; y -= 0.1)
{
m = cos(y)*10;
for( x = 1; x < m; x++)
printf("");
printf("*");
for(; x < 62-m; x++)
printf("");
printf("*\n");
}
return 0;
}
显示不出来
屏幕上用“*”显示0-360度的余弦函数cos(x)曲线#include #include int main (){double y;int x,m; for( y = 1; y >= -1; y -= 0.1){m = cos(y)*10;for( x = 1; x < m; x++) printf("");printf("*");for(; x < 62-m; x++)printf("");printf("*\n");}
修改一下程序:1.用弧度制进行计算,2.每行换行
#include
#include
#define PI 3.1415926
int main()
{
double y;
int x,m;
for( y = 2*PI; y >= -2*PI; y -= 0.1)
{
m = cos(y)*20+40;
for( x = 1; x < m; x++) printf(" ");
printf("*\n");
}
return 0;
}
如果需要横着显示,就不能用cos函数了,需要用反余弦函数:
#include
#include
#define PI 3.1415926
int main()
{
double y;
int x,m;
for( y = 1; y >= -1; y -= 0.1)
{
m = 40-acos(y)*10;
for( x = 1; x < m; x++) printf(" ");
printf("*");
for( x = 1; x < (40-m)*2; x++) printf(" ");
printf("*\n");
}
return 0;
}