C语言实现源码,供参考!
余弦函数:
#include
<
stdio.h
>
#include < math.h >
void main()
{
double y;
int x,m;
for (y = 1 ;y >=- 1 ;y -= 0.1 ) /* y为列方向,值从1到-1,步长为0.1 */
{
m = acos(y) * 10 ; /* 计算出y对应的弧度m,乘以10为图形放大倍数 */
for (x = 1 ;x < m;x ++ ) printf( " " );
printf( " * " ); /* 控制打印左侧的 * 号 */
for (;x < 62 - m;x ++ )printf( " " );
printf( " *\n " ); /* 控制打印同一行中对称的右侧*号 */
}
}
#include < math.h >
void main()
{
double y;
int x,m;
for (y = 1 ;y >=- 1 ;y -= 0.1 ) /* y为列方向,值从1到-1,步长为0.1 */
{
m = acos(y) * 10 ; /* 计算出y对应的弧度m,乘以10为图形放大倍数 */
for (x = 1 ;x < m;x ++ ) printf( " " );
printf( " * " ); /* 控制打印左侧的 * 号 */
for (;x < 62 - m;x ++ )printf( " " );
printf( " *\n " ); /* 控制打印同一行中对称的右侧*号 */
}
}
正弦函数:
#include
<
stdio.h
>
#include < math.h >
main(){
double y;
int x,m,i;
printf( " y=sin(x) [0<x<2*pi]\n " );
for (y = 1 ;y >=- 1 ;y -= 0.1 ){ /* y为列方向,值从1到-1,步长为0.1 */
if (y >= 0 ){
m = asin(y) * 10 ; /* 计算出y对应的弧度m,乘以10为图形放大倍数 */
for (x = 1 ;x < m;x ++ )printf( " " );
printf( " * " ); /* 控制打印 * 号 */
for (;x < 31 - m;x ++ )printf( " " );
printf( " *\n " );} /* 控制打印同一行中对称的*号 */
else {
m =- 1 * asin(y) * 10 ;
for (i = 0 ;i < 32 ;i ++ )printf( " " );
for (x = 1 ;x < m;x ++ )printf( " " );
printf( " * " );
for (;x < 31 - m;x ++ )printf( " " );
printf( " *\n " );
}
}
}
#include < math.h >
main(){
double y;
int x,m,i;
printf( " y=sin(x) [0<x<2*pi]\n " );
for (y = 1 ;y >=- 1 ;y -= 0.1 ){ /* y为列方向,值从1到-1,步长为0.1 */
if (y >= 0 ){
m = asin(y) * 10 ; /* 计算出y对应的弧度m,乘以10为图形放大倍数 */
for (x = 1 ;x < m;x ++ )printf( " " );
printf( " * " ); /* 控制打印 * 号 */
for (;x < 31 - m;x ++ )printf( " " );
printf( " *\n " );} /* 控制打印同一行中对称的*号 */
else {
m =- 1 * asin(y) * 10 ;
for (i = 0 ;i < 32 ;i ++ )printf( " " );
for (x = 1 ;x < m;x ++ )printf( " " );
printf( " * " );
for (;x < 31 - m;x ++ )printf( " " );
printf( " *\n " );
}
}
}
本文转自施杨博客园博客,原文链接:http://www.cnblogs.com/shiyangxt/archive/2008/09/14/1290827.html,如需转载请自行联系原作者