用C#语言编程绘图输出y=a*sin(c*x + b)
来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/06/23 13:30:53
用C#语言编程绘图输出y=a*sin(c*x + b)
要求:
系数a,b和c是可以变化的,可考虑是从键盘输入的,或通过Main方法参数传递的;
x的取值范围在0~4π之间,x,y值采用四舍五入;结果如下图:
#
# #
# # #
# #
#
要求:
系数a,b和c是可以变化的,可考虑是从键盘输入的,或通过Main方法参数传递的;
x的取值范围在0~4π之间,x,y值采用四舍五入;结果如下图:
#
# #
# # #
# #
#
![用C#语言编程绘图输出y=a*sin(c*x + b)](/uploads/image/z/8250116-68-6.jpg?t=%E7%94%A8C%23%E8%AF%AD%E8%A8%80%E7%BC%96%E7%A8%8B%E7%BB%98%E5%9B%BE%E8%BE%93%E5%87%BAy%3Da%2Asin%28c%2Ax+%2B+b%29)
啥?控制台输出正弦函数曲线?头一次遇到这种题,试着做了一下. 参考代码:using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Title = "绘制 y = a * sin(c * x + b) 正弦曲线图像";
while (true)
{
try
{
double a, b, c;
Console.Write("请输入 a:");
a = Convert.ToDouble(Console.ReadLine());
if (a == 0) throw new Exception("a 不能为0.");
Console.Write("请输入 b:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入 c:");
c = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
// 纵坐标 y 取值从 -a 到 a
// 0.2 越小画的范围越大,曲线越精细
for (double y = -a ; y <= a; y += 0.2)
{
// 横坐标 x 取值从 0 到 4π
for (double x = 0; x <= Math.PI * 4; x += 0.2)
{
if (Math.Abs(y + Math.Sin(c * x + b)) < 0.092) // 一个字符高度大约0.46,0.092 = 0.2 * 0.46
Console.Write("#");
else
Console.Write(" ");
}
Console.WriteLine();
}
}
catch (Exception ex)
{
Console.WriteLine("\r\n错误!\r\n" + ex.ToString());
}
Console.WriteLine("\r\n按任意键继续 ...");
Console.ReadKey();
Console.Clear();
}
}
}
} 运行结果:![](http://img.wesiedu.com/upload/c/b8/cb8cf064e9b14c692c3387692b3bfe16.jpg)
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Title = "绘制 y = a * sin(c * x + b) 正弦曲线图像";
while (true)
{
try
{
double a, b, c;
Console.Write("请输入 a:");
a = Convert.ToDouble(Console.ReadLine());
if (a == 0) throw new Exception("a 不能为0.");
Console.Write("请输入 b:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入 c:");
c = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
// 纵坐标 y 取值从 -a 到 a
// 0.2 越小画的范围越大,曲线越精细
for (double y = -a ; y <= a; y += 0.2)
{
// 横坐标 x 取值从 0 到 4π
for (double x = 0; x <= Math.PI * 4; x += 0.2)
{
if (Math.Abs(y + Math.Sin(c * x + b)) < 0.092) // 一个字符高度大约0.46,0.092 = 0.2 * 0.46
Console.Write("#");
else
Console.Write(" ");
}
Console.WriteLine();
}
}
catch (Exception ex)
{
Console.WriteLine("\r\n错误!\r\n" + ex.ToString());
}
Console.WriteLine("\r\n按任意键继续 ...");
Console.ReadKey();
Console.Clear();
}
}
}
} 运行结果:
![](http://img.wesiedu.com/upload/c/b8/cb8cf064e9b14c692c3387692b3bfe16.jpg)
用C#语言编程绘图输出y=a*sin(c*x + b)
怎样编写一个C#语言编程求 y=x,x=sin(x)的三个根?
c语言编程 输入x 输出y y=表达式1 ,-5
C语言编程问题 编程任意输入两个实数a和b,计算下面函数的值,并输出y值. a-b a>b y= a/b a
c语言 sin(x)+cos(x)编程
从键盘输入两个实数a和x,按公式计算并输出y的值:(c语言) y=a^5+sin(ax)+ln(a+x)+e^ax
输出X,求出并输出X的绝对值 用C语言编程
用C语言编程输出如下图形
x的值是从1到10的整数,f(x)=x*x-5*x+sin(x),用C语言编程求出每一个f(x)并输出最大值
C语言编程,用C语言编写下面这个方程.方程:x²(x-A)=B 注:A和B都是已知常数,x是待求未知数.
C语言编程问题 输入a,b,c三个数 最后 要求输出最大的.
C语言编程 输入二次方程的三个系数 a b c 输出二次方程的根