当前位置: > 如何使用循环语句缩短程序...
题目
如何使用循环语句缩短程序
subplot(521);
plot(index,a1);
subplot(522);
plot(index,a2);
subplot(523);
plot(index,a3);
subplot(524);
plot(index,a4);
subplot(525);
plot(index,a5);
subplot(526);
plot(index,d1);
subplot(527);
plot(index,d2);
subplot(528);
plot(index,d3);
subplot(529);
plot(index,d4);
subplot(5,2,10);
plot(index,d5); 以上是程序的一部分,我想问下可不可以把这段程序用循环语句简练的表达出来,这样实在是太麻烦了,麻烦大神老师们给看看,跪谢!

提问时间:2020-08-26

答案
也许可以这样:
1、subplot语句因为其参数是有规律地递增,所以是完全可以用循环表达的.
2、plot语句,其中的index和第二个参数是常量还是变量?如果index是变量,则可以在每次循环中进行更新.第二个参数,完全可以把a1, a2, a3, a4,a5, d1,等等,这样的参数事先组成一个数组,然后每次循环读取对应的值,然后数组的索引递增,这样就能把两个语句都放到循环中了.
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.